Rails:flash消息在url中显示为param

Sso*_*esS 1 flash ruby-on-rails

大家好我的所有flash消息都以正常方式工作,但我的一个控制器中有一个动作,其中flash消息不起作用.

这是观点:

<%= form_tag update_status_order_path(update_status), method: :put do |f| %>
    <%= select(:order, :status, [['Active', 1], ['Inactive', 0]]) %>
    <%= submit_tag "Update" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

这是控制器动作

def update_status
        if @order.update_order_status! params[:order][:status] 
            redirect_to show_orders_ofert_path @order.ofert, success: "Updated!."
        else
            redirect_to show_orders_ofert_path @order.ofert, error: "Error."
        end
    end
Run Code Online (Sandbox Code Playgroud)

当我发送表单时,操作正确执行,但flash消息没有显示在布局中,而是作为param显示在url中,只需单击Update按钮后重新加载并显示如下所示的url:

http://localhost:3000/oferts/48/show_orders?success=Updated!
Run Code Online (Sandbox Code Playgroud)

我已经尝试将put更改为patch但是它没有用,甚至改变了使用respons_to块的动作但它没有用,任何想法?

这个问题只发生在特定的操作上,因为我通过其他操作可以正常显示Flash消息.

谢谢

inf*_*sed 7

成功和错误键被用作show_orders_ofert_path的参数,因为没有括号.在路径助手参数周围添加括号:

redirect_to show_orders_ofert_path(@order.ofert), success: "Updated!."
Run Code Online (Sandbox Code Playgroud)

  • Ruby解析器错误地将所有参数解析为show_orders_ofert_path方法的参数.它没有办法告诉你想要什么,除非你添加一些括号来区分`sucess:'Updated!.'`参数与`redirect_to`而不是'show_orders_ofert_path`.合理? (2认同)