Ruby on rails ActionController::未知信息格式Rails 5
在我的config/routes.rb中,我有:Ruby on rails ActionController::未知信息格式Rails 5,ruby-on-rails,Ruby On Rails,在我的config/routes.rb中,我有: Rails 5.2 books_author POST /books_author(.:format) books#author 当我运行rake路线时,我得到: post 'books_author', to: 'books#author' 在我的app/controllers/books_controller.rb中,我有: Rails 5.2 books_author POST /books_author(.:format) boo
Rails 5.2
books_author POST /books_author(.:format) books#author
当我运行rake路线时,我得到:
post 'books_author', to: 'books#author'
在我的app/controllers/books_controller.rb中,我有:
Rails 5.2
books_author POST /books_author(.:format) books#author
在我的视图/books/index.html.slim中,我有以下内容:
def author
@books_collection = params[:books_collection]
@author_notes = params[:author_notes]
respond_to do |format| -----------------------------> this is line 27
format.js
end
end
单击“作者详细信息”链接时,出现以下错误:
..........
td
= form_tag books_author_path do
= hidden_field_tag 'books_collection', books_collection
= hidden_field_tag 'author_notes', author_notes
= submit_tag 'Author Details'
有什么想法吗?在您的控制器中,您告诉它返回JS作为响应,但您提供了.html.slim,这意味着它应该返回html或JS,您可以更改以下行
ActionController::UnknownFormat in BooksController#author
ActionController::UnknownFormat
Extracted source (around line #27): (line 27 is highlighted in red)
@author_notes = params[:author_notes]
respond_to do |format|---------------------------------> this is line 27
format.js
end
或
或者我认为删除以下行是安全的,然后它会自动选择默认视图
format.html { }
format.js { }
它将自动使用html版本显示。您的表单必须是
远程:true
才能返回javascriptYes,当我将remote::true添加到表单\u tag books\u author\u path Dot链接在一个视图中,但返回到另一个视图时,这一点就起作用了。远程::真有效