Rails match routes with slugs without using ID in link
routes, ruby-on-rails-3, slug
Solution
In your routes use this
match "/:slug" => "pages#show"
And in your controller find the page by slug using this
@page = Page.find_by_slug(params[:slug])
Problem
In my routes file I can easily put together a match that looks like this and works just fine ``` match '/:slug/:id' => "pages#show", :id => :id ``` the link in the view that this works for is ``` link_to n.name, "/" + n.slug + "/" + n.id.to_s ``` I'd rather not include the ID number in the URL so I was hoping to do something like ``` match '/:slug' => "pages#show", :slug => :slug ``` But the problem is this doesn't provide the id to the pages show controller. Is there some way of using the :slug to match it to the page in the database with this slug to find the :id so I can pass the :id to the controller?