出于 RESTful 的目的,我的路由是这样的:
路线.rb
match 'shops/:sort/:genre/:area', :to => 'shops#index'
但是如果流派是空的呢?不会重定向到example.com/shops/newest_first//california
?
我该如何解决这种路由和参数问题?谁能给我一个很好的例子?
看法
<%= form_tag shops_path, :method => :get do %>
<%= select_tag :sort, options_from_collection_for_select(Sort.all, 'id', 'name', params[:sort]), :prompt => "Newest first" %>
<%= select_tag :genre, options_from_collection_for_select(Genre.all, 'id', 'name', params[:genre]), :prompt => "all" %>
<%= select_tag :area, options_from_collection_for_select(Area.all, 'id', 'name', params[:area]), :prompt => "all" %>
<% end %>
另一种观点