2014-08-31 27 views
2

我有一個項目,用戶可以下載文件。現在,我需要另一個頁面來顯示所有用戶。所以,我在我的addfiles_controller中添加了一個方法all_users。我也有一個觀點頁面all_users.html.erb。但是這個問題與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

你不應該寫all_usersonly,因爲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 
+0

非常感謝。 – Mezbah 2014-08-31 14:30:08