1

This url has parameter(:sort) in its url. I'm sure it's against the convetion of RoR.

http://example.com/shops?sort=updated

Then how can I make it RESTful?

Creating new action called 'sort_update' in shops_controller.rb? and make use access to http://example.com/shops/sort_update/?

cat
  • 749
  • 10
  • 22
  • _I'm sure it's against the convetion of RoR._ Why using query string isn't RESTful ? See http://stackoverflow.com/questions/776448/pagination-in-a-rest-web-application for some answers – tight Jan 08 '13 at 09:57

1 Answers1

2

In this case, I would add a manual route to my routes file

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

Make sure you add this above

resources :shops

That way, an url like /shops/by_updated will be routed to the index action but the parameter sort will additionally have the value 'updated'.

moritz
  • 25,477
  • 3
  • 41
  • 36
  • Thanks. Do you think following RESTful will be good attitude to Google SEO? – cat Jan 08 '13 at 10:33
  • I do think that it'll work better than the query string alternative. – moritz Jan 08 '13 at 11:43
  • !!! Thanks a lot what if you had more than 2 parameters??? like params[:sort] and params[:genre]??? – cat Jan 08 '13 at 11:52
  • Well nothing keeps you from `match 'shops/by_:sort/:genre'`. You can add as many as you want. I can't tell you though how google looks at an url with 15 parameters incorporated. – moritz Jan 08 '13 at 11:57
  • Thanks!! but what if the parameter was empty? If I made `match 'shops/by_:sort/:genre/:area` and what if :genre was empty??? It will be `shops/by_updated//california` Isn't it strange? – cat Jan 08 '13 at 12:15