【问题标题】:Implementing REST-api with different defaults format使用不同的默认格式实现 REST-api
【发布时间】:2011-07-18 11:38:57
【问题描述】:

我有一个名为 password_resets 的小 REST 控制器,它只有创建、显示和更新方法。

在 routes.rb 中:

resources :password_resets, :only => [:create, :show, :update]

我希望默认情况下可以使用 json 操作其中一个操作,但其他操作不能。对于我能做的所有动作:

scope :defaults => {format: 'json'} do
  resources :password_resets, :only => [:create, :show, :update]  
end

但是如何只为一个动作做同样的事情呢?

【问题讨论】:

    标签: ruby-on-rails json rest


    【解决方案1】:

    您可以使用多行来设置不同的格式:

    resources :password_resets, :only => [:create, :update]
    resources :password_resets, :only => [:show], :defaults => { :format => 'json' }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      • 2014-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多