【问题标题】:How can I disable some of the routes for resources on rails 3?如何禁用 Rails 3 上的某些资源路由?
【发布时间】:2013-01-05 06:00:04
【问题描述】:

我想将模型定义为获取所有 REST URL 的资源。

但是,我想禁用一些生成的路由(例如,DELETE)。是否有一个简单的 API,或者我只需要单独声明所有路由?

【问题讨论】:

    标签: ruby-on-rails-3 rest routes


    【解决方案1】:

    你有两种方法可以做到这一点

    在 config/routes.rb 中

    1) 作为@emm,建议只定义你想要的路线

    2) 对 exclude 路由使用 except 关键字

    Ex: Excluding destroy action 
    
    resources :books, :except => [:destroy]
    

    read more here

    HTH

    【讨论】:

      【解决方案2】:

      routes.rb 中的类似内容:

      resources :photos, :only => [:index, :show]
      

      查看更多here

      【讨论】:

        【解决方案3】:

        您还可以排除以下特定操作: resources :articles, except: :destroy

        【讨论】:

          猜你喜欢
          • 2015-11-21
          • 2011-05-23
          • 1970-01-01
          • 1970-01-01
          • 2017-12-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多