Rails Routes - Limiting the available formats for a resource

后端 未结 6 1907
孤城傲影
孤城傲影 2020-11-30 08:31

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

6条回答
  •  旧时难觅i
    2020-11-30 09:23

    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

提交回复
热议问题