Ruby on rails 控制器未接收到对象id

Ruby on rails 控制器未接收到对象id,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我正在尝试使用将category.id传递给商店/索引控制器 <% Category.all.each do |category| %> <div><%= link_to category.name.titleize, shop_index_path :category_id => category.id %></div> <hr> <% end %> 有人知道这是为什么吗

我正在尝试使用将category.id传递给商店/索引控制器

<% Category.all.each do |category| %>
        <div><%= link_to category.name.titleize, shop_index_path :category_id => category.id  %></div>
        <hr>
    <% end %>
有人知道这是为什么吗

编辑:这是我使用的路线

get 'shop/index'
应该是

<%= link_to category.name.titleize, shop_index_path(category.id) %>

应该是

<%= link_to category.name.titleize, shop_index_path(category.id) %>

您当然可以使用:

shop_index_path(category.id)
然后加载:

Category.find(params[:id]).products

当然你可以用:

shop_index_path(category.id)
然后加载:

Category.find(params[:id]).products

尝试添加
参数

shop_index_path(params: { category_id: category.id })
get 'shop/index/:category_id', to: 'shop#index'
您需要优化传递
参数的路由

shop_index_path(params: { category_id: category.id })
get 'shop/index/:category_id', to: 'shop#index'
现在您可以将
category\u id
传递给路径帮助器,如下所示:

shop_index_path(category.id)

尝试添加
参数

shop_index_path(params: { category_id: category.id })
get 'shop/index/:category_id', to: 'shop#index'
您需要优化传递
参数的路由

shop_index_path(params: { category_id: category.id })
get 'shop/index/:category_id', to: 'shop#index'
现在您可以将
category\u id
传递给路径帮助器,如下所示:

shop_index_path(category.id)

尝试添加参数
shop_index_path(参数:{:category_id=>category.id})
尝试添加参数
shop_index_path(参数:{:category_id=>category.id})
在看到RSB的答案后,这可能不起作用-你能发布你的路线吗?谢谢你的回复-你能发布你的路线吗?很好,但我仍然想查看你的路线-你所做的不是常规啊,我明白了,添加我现在使用的路线在看到RSB的答案后,这可能不起作用-你能发布你的路线吗?谢谢回复-你能发布你的路线吗?很好,但我仍然想查看你的路线-你所做的不是常规啊,我明白了,添加我现在使用的路线