Montag, 6. Oktober 2008

Renanaming URL routes

Renaming the URL'S defaults generated with the controllers.

i.e you have a resource you address in your code:

<% link_to("award", certificate_path(1)%>

This might be because you actually only have one certificate. You have the link on the page showing Awards, but when the user clicks on the link the URL will show:

/certificates/show/1

To change this you need to edit the routes.rb

map.resources :certificates

to the following:

map.the_certificate 'award', :controller => certificates, :action => 'show', id => 1
map.resources :certificates


Now you can change:

<% link_to("award", certificate_path(1)%> to <% link_to("award", the_certificate_path %>

NOTE 1:

doing this does not work properly:

map.certificate 'award', :controller => certificates, :action => 'show', id => 1
map.resources :certificates


i.e. trying to overwrite mapped resource with the same name to point to the proxy url.
It messes up when you render a form with somthing like
<% form for @certificate %>

NOTE:

Whenever you make any changes to the routes.rb file you will need to restart your server!!!!

Keine Kommentare: