尝试获取路由,以便传递一个字符串,我可以在控制器中使用该字符串来查询数据库。
controller:
def sales
@sales= Micropost.where(:sale_name => params[:sale])
@sales = Sale.sales
end
View:
<%= link_to('See all', :controller =>"microposts", :action => "sales", :sale => sales_item.sale_name) %>
Routes.rb
match '/sales/:sale', :to => 'microposts#sales'
答案 0 :(得分:0)
将路线更改为match 'microposts/sales' => 'microposts#sales'
,您可以将参数传递给该操作。
You can also make it a named route,看起来像match 'sales' => 'microposts#sales', :as => :sales
。有了这个,您将获得sales_url
和sales_path
。您可以将其用作例如sales_path(:sale => sales_item.sale_name)
。
希望这有帮助。