views:

26

answers:

2

hi...

i want to change the default route in RoR to what i want: consider the following example...

:controller/:action/:id

which will give you the route in the browser as: http://localhost:3000/controller/action/id

now i want to change it to...

http://localhost:3000/this-is-what-i-want/id

we can get an alias for the controller and the action as well like...

resources :controller, :as => "my-custom-name"

and if you want to have the alias for the action, then

resources :controller, :path_names => { :action => 'my-custome-name-1', :action => 'my-custome-name-2' }

BUT i want to change the controller and the action at once... if u noticed the above http://localhost:3000/this-is-what-i-want/id path in the question...

need help... thanks in advance...

A: 

You want to be using Rest routes, rather than controller/action

I'm going to use "balls" instead of "this-is-what-i-want"

resources :balls

Then, when you link to a ball, do link_to(ball.name, ball).

This will give you a link of http://localhost:3000/balls/45

This rails rest cheatsheet is a good start.

Jesse Wolgamott
A: 

You need a named route.

In Rails2:

map.a_name 'this-is-what-i-want/:id', :controller => 'controller_name', :action => 'action_name'

In Rails3:

match 'this-is-what-i-want/:id' => 'controller_name#action_name'
Yannis
now what if i want: map.a_name 'this-is-what-i-want/dynamic-name/:id', :controller => 'controller_name', :action => 'action_name'... how em i gona set the link for the "dynamic-name" in rails...?
Jamal Abdul Nasir
Then follow the advice of Jesse Wolgamott and use rest routes
Yannis