cat
cat

Reputation: 749

How can I make this RESTful when it's requested with few parameters at once?

I made my routing just like this. But what if genre was empty?
Isn't it going to redirect to example.com/shops/newest_first//california?
How can I solve this kind of routing and parameters problem??

routes.rb

match 'shops/:sort/:genre/:area', :to => 'shops#index'

view

<%= 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 %>

Another View

Upvotes: 0

Views: 40

Answers (1)

Nicholas Lindley
Nicholas Lindley

Reputation: 161

I would consider using GET params for things like area and sort since you are filtering indexes of other resources. You might also check the the section on Dynamic Segments in the guides, although that won’t help with the empty segment in the middle.

Upvotes: 1

Related Questions