ale
ale

Reputation: 11830

Using routing (?) to make GET request in Rails so ID doesn't show

I have a link in one view myapp/locations that goes to myapp/statistics?id=1 (statistics for location with ID 1) which works fine but it doesn't look pretty. I think I've seen people do this sort of thing without needing the ?id=1? I could use a POST but this is not RESTful. Is there a way I can use routing to allow the user to go to myapp/statistics?id=1 but have the user see myapp/statistics?

Many thanks.

Upvotes: 0

Views: 51

Answers (2)

usha
usha

Reputation: 29349

You can make it go to myapp/locations/1/statistics(which is the rails way) if you scope statistics with locations in your route

resources :locations do
  resources :statistics
end

Upvotes: 0

Ermin Dedovic
Ermin Dedovic

Reputation: 907

Check out friednly_id gem. It makes it easier for you to have something like this: myapp/statistics/Germany. Check out Railscasts video about this gem.

Upvotes: 1

Related Questions