views:

29

answers:

1

I have a series of resources that I want only available if accessed via the JS format. Rails' route resources gives me the formats plus the standard HTML. Is there a way to specify that only the JS format routes be created?

+1  A: 

You just add constraints about format :

resources :photos, :constraints => {:format => /(js|json)/}
shingara
Unless I'm doing something wrong, that still allows me to access /photos as :html. I get the missing template message, when I'd expect a missing route exception. Thoughts?
Eric M.
Shouldn't that be `/(js|json)/`?
Garrett
Yeah, I caught that and changed it. Still doesn't work for me. I have resources :members, :controller => 'homes/members', :constraints => {:format => /js/}
Eric M.