使用:只在路线中帮助

时间:2014-08-31 14:13:16

标签: ruby-on-rails ruby-on-rails-4 routes

我有一个用户可以下载文件的项目。现在,我想要另一个页面来显示所有用户。所以,我在addfiles_controller中添加了一个方法all_users。我还有一个查看页面all_users.html.erb。但是ploblem与routes.rb文件有关。在这里,我想确保用户只能使用:index, :new, :create, :destroy, :all_users路径。 我该如何设置:在我的routes.rb文件中只有帮助器,比如

resources :addfiles, only: [:index, :new, :create, :destroy, :all_users]

我的routes.rb文件::

  resources :addfiles do
    collection  do
      get 'all_users'
    end
  end

1 个答案:

答案 0 :(得分:1)

您不应该将all_users写入only,因为only/except仅与index, show, new, edit, create, update, destroy默认定义的标准操作resources相关

  resources :addfiles, only: [:index, :new, :create, :destroy] do
    collection  do
      get 'all_users'
    end
  end