簡體   English   中英

僅在Rails生產中使用ActionController :: UnknownFormat

[英]ActionController::UnknownFormat in Rails production only

當我單擊“檢查”按鈕時,我試圖顯示一條即顯消息,而無需重新呈現整個頁面。

在開發模式下,下面的代碼可以工作,但在生產模式下不起作用。 而不是停留在main.html上並顯示Flash消息,而是將我重定向到“檢查”頁面。

日志控制台為我提供了以下調試消息:

在2ms內完成406不可接受(ActiveRecord:0.0ms)

ActionController :: UnknownFormat(ActionController :: UnknownFormat):
app / controllers / my_controller.rb:105:在`check'中

我錯過了一些在生產模式下工作的東西嗎?

main.html.erb

<div class="check"><%= render partial: 'check' %></div>
<%= f.submit :Check, class: "btn btn-default", remote: true, formaction: app_check_path %>


_check.html.erb

<div id = "notice">
</div>


check.js.erb

$("#notice").html('<p style="color: green;"><%= flash[:notice] %></p>').show().delay(5000).hide(0);


my_controller.rb

def check
   notice = "NOTICE!"
   respond_to do |format|
       format.js do
          flash[:notice] = notice
       end
   end
end


routes.rb

get 'app/check'
post 'app/check'

嘗試以下

_check.html.erb

<% flash.each do |msg| %>
    <%= msg.html_safe %>
<% end %>

check.js.erb

$("#notice").html('<%= escape_javascript(render("check")) %>');

my_controller.rb

更改此行

notice = "<p style='color: green;'>NOTICE!</p>"

希望對大家有幫助

您需要以JS格式提交表單,以呈現JS類型的響應!

暫無
暫無

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

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