views:

162

answers:

3

Is this possible?

def to_param
  "#{id}%2F#{slug}"
end

This works in Chrome and Safari, but if Firefox you see the "%2F" in the address bar. Is there a cleaner way?

+1  A: 

Have a look at Friendly ID -- it will eliminate the ID entirely and just use the slug. It is Rails 3 compatible as well.

bensie
+1  A: 

Ok I tried this just now you won't need this:

def to_param
  "#{id}/#{slug}"
end

In routes.rb (replace what you want with what you need)

match "/expenses/:id/:slug" => "expenses#show", :as => :expense

Your link_to should look like this now

= link_to "something", expense_url(:id => expense.id, :slug => expense.slug)

hope this helps a bit

Hugo
A: 

maybe something like this can help you

match "/foo/:id", :to => redirect("/bar/%{id}s")

check out the section The "Redirect Method" in this article about rails3 and routes

http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/

server info