【问题标题】:Redirect from index.html.erb to a controller method with params从 index.html.erb 重定向到带有参数的控制器方法
【发布时间】:2016-03-23 11:00:23
【问题描述】:

我有一个使用简单形式的部分 _filter.html.erb。第一行是:

<%= simple_form_for :filter, url: index_panel_path, :method => "get", :html => { :id => "search_by_id"} do |f| %>

因此,在单击过滤器按钮时,它会使用参数 [:filter] 调用 index_panel_path。 index.html.erb 有这一行:

<li><a href=<%= grocery_panel_path %> >Grocery Panel</a></li>

这会调用控制器中的grocery_panel 方法。问题是我在 index.html 中获取了 params[:filter],但在杂货店方法中,params[:filter] 为 nil。知道如何将参数发送到那里吗?

【问题讨论】:

    标签: html ruby-on-rails ruby-on-rails-4 parameter-passing embedded-ruby


    【解决方案1】:

    像这样手动传递:-

    <li><a href=<%= grocery_panel_path(:filter => "some_value") %> >Grocery Panel</a></li>
    

    【讨论】:

    • 成功了!非常感谢。
    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 2013-06-17
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    相关资源
    最近更新 更多