Rails make all routes default to format: :json

后端 未结 2 552
天命终不由人
天命终不由人 2021-01-18 08:50

Can you make all routes default to json?

I have the following for an api scope but am wondering if you can do the same for the global scope?

         


        
相关标签:
2条回答
  • 2021-01-18 09:46

    According to Rails docs, in your config/routes.rb file:

    defaults format: :json do
      resources :photos
    end
    
    0 讨论(0)
  • 2021-01-18 09:49

    Use constraints

    constraints format: :json do
      resources :users
    end
    

    or

    resources :users, :defaults => { :format => 'json' }
    
    0 讨论(0)
提交回复
热议问题