簡體   English   中英

ActionController::UnknownFormat Rails 5

[英]ActionController::UnknownFormat Rails 5

Rails 5.2

在我的 config/routes.rb 中,我有:

post 'books_author', to: 'books#author'

當我運行 rake 路線時,我得到:

books_author POST /books_author(.:format) books#author

在我的 app/controllers/books_controller.rb 中,我有:

def author
  @books_collection = params[:books_collection]
  @author_notes = params[:author_notes]
  respond_to do |format| -----------------------------> this is line 27
    format.js
  end
end

在我的 views/books/index.html.slim 中,我有以下內容:

..........
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'

當我單擊“作者詳細信息”鏈接時,出現以下錯誤:

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

有任何想法嗎?

在您的控制器中,您告訴它返回 JS 作為響應,但您提供 .html.slim 這意味着它應該返回 html 或 JS 您可以更改以下行。

 format.html

或者

format.html {   }
format.js { }

或者我認為刪除以下幾行是安全的,然后它會自動選擇默認視圖。

 respond_to do |format| 
    format.js
  end

它將自動以 html 版本顯示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM