views:

30

answers:

2

Hi!

Just as the topic say. I want to change the default controller/:id routing to controller/:name instead in Rails 3. In Rails 2 you used named routing with something like this:

config/routes.rb

map.location 'location/:name', 
  :controller => 'your_controller', :action => 'your_action'

alternate named route

map.location 'goto/:name', :controller => 'location', :action => 'your_action'

examples of URL specification in a view

<%= link_to 'foo', location_url({:name => 'foo'}) %>
<%= link_to 'bar', location_path({:name => 'bar'}) %>

But i'm sure there is another (better) way in Rails 3.

A: 

Not sure but may this would help you.

match 'user_delete/:name', :to => 'sessions#destroy'

this is same as

map.user_delete '/user_delete/:name', :controller => 'sessions', :action => 'destroy'

Mayank Jaimini
A: 

Try this:

match 'location/:name' => 'your_controller#your_action', :as => location
jpartogi