Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Named Routing in Rails (getting rid of the ids)

Lifted from Semergence
(http://www.semergence.com/archives/2005/12/01/10/02/32/)

In config/routes.rb:

map.projectproject/:projtitle’ :controller =>project’, :action =>show’


In app/controllers/project_controller.rb:
   def show
     @project = Project.find(:first,
                             :conditions => [’title = ?’,params[:projtitle]])end


Or something like that. Assuming your project titles are unique. Then
you can also use project_url (since you have map.project in routes.rb)
for urls in your views, e.g.

   <% for project in @projects %>
   <%= link_to project.title,
               project_url(:projtitle => project.title) %>
    …
   <% end %>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS