2012-11-20 21 views
1

我有一个Category模型,其中有很多Products链接到活动管理器中的嵌套资源收集索引页面

我想在Category索引页面中添加一个链接,链接到产品索引的预过滤版本。像这样:

link_to "View Products in This Category", admin_products(:product_id => self.id) 

但似乎无法找到任何明确的文件如何做到这一点。

回答

1
link_to "View Products in This Category", :controller => "products", :action => "index", 'q[product_category_id_eq]' => "#{p.id}".html_safe 
0

而且这个怎么样:

link_to "View Products in This Category", admin_products(:category_id => category.id) 

如果您在类别索引页面,你应该有类似的东西在你看来:

<% @categories.each do |category| %> 
    <%= category.name %> 
    ... 
    <%= link_to "View Products in This Category", admin_products(:category_id => category.id) %> 
<% end %> 
7

编号建议做它宁静的方式,activeadmin具有内置的这种类型的功能,因为它的内置的继承资源,其具有控制器belongs_to方法,例如

管理/ categories.rb

ActiveAdmin.register Category do 

    #assuming you have a category name field 
    index do 
    column "Name" do |category| 
     link_to(category.name, admin_category_products_path(category) 
    end 

    end 

end 

管理/ products.rb

ActiveAdmin.register Product do 

    belongs_to :category 

end