Rails Routes - Limiting the available formats for a resource

后端 未结 6 1909
孤城傲影
孤城傲影 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条回答
  •  一个人的身影
    2020-11-30 09:04

    None of the above solutions worked for me. I ended up going with this solution:

    post "/test/suggestions", to: "test#suggestions", :constraints => -> (req) { req.xhr? }
    

    Found on https://railsadventures.wordpress.com/2012/10/07/routing-only-ajax-requests-in-ror/#comment-375

提交回复
热议问题