繁体   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