2

I've got a named route called profile and I would like to be able to access it as json. But when I look at my rake routes output I see that the (.:format) is missing. How do I add it to a named route?

user GET    /users/:id(.:format)    {:action=>"show", :controller=>"users"}
profile     /:username              {:action=>"show", :controller=>"users"}

Thanks in advance!

Alfred
  • 7,071
  • 4
  • 27
  • 35

1 Answers1

7

Add .format in your path specification, like this:

map.profile '/:profile.:format', :controller => 'users', :action => 'show'

Then you'll end up with:

profile    /:profile(.:format)     {:action=>"show", :controller=>"users"}
Thorbjørn Hermansen
  • 3,522
  • 1
  • 21
  • 12
  • I tried map.profile '/:profile(.:format)', :controller => 'users', :action => 'show' and was so surprised it didn't work. I think it should! :-) – Docunext Aug 03 '12 at 17:05