Implementing REST-api with different defaults format
I have a little REST-controller named password_resets, it has o开发者_开发技巧nly create, show and update methods.
In routes.rb:
resources :password_resets, :only => [:create, :show, :update]
and I want one of the actions can manipulate with json by default, but others not. For all actions I can do:
scope :defaults => {format: 'json'} do
resources :password_resets, :only => [:create, :show, :update]
end
but how to do the same only for one action?
you can use multiple lines to setup differents formats:
resources :password_resets, :only => [:create, :update]
resources :password_resets, :only => [:show], :defaults => { :format => 'json' }
精彩评论