Alex Rivera | Logout

Rails Routes - Limiting the available formats for a resource

Asked 2010-09-09T17:54:48.027
33

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?

Edit
Report

1 Answer

65

You must wrap those routes in a scope. Constraints unfortunately don't work as expected in this case.

This is an example of such a block...

scope :format => true, :constraints => { :format => 'json' } do
  get '/bar' => "bar#index_with_json"
end

More information can be found here: https://github.com/rails/rails/issues/5548

answered 2012-08-03T07:28:24.797

Your Answer