Con*_*nor 14 devise ruby-on-rails-3.1
我试图覆盖默认设计注册控制器的一些功能,以便只有某些用户可以为其他用户创建帐户.因此,在controllers/users文件夹下名为registrations_controller.rb的文件中,我有以下内容
class Users::RegistrationsController < Devise::RegistrationsController
before_filter :check_permissions, :only => [:new, :create, :cancel]
skip_before_filter :require_no_authentication
def check_permissions
authorize! :create, resource
end
end
Run Code Online (Sandbox Code Playgroud)
在我的路线文件中我有
devise_for:users,:controllers => {:registrations =>'users/registrations'}
当我尝试转到users/sign_up url时,我得到一个路由错误'uninitialized constant Users :: RegistrationsController'.
所以真正让我了解的是,我在rails 3应用程序中使用了几乎完全相同的功能而没有任何问题.我看了一些类似于此的其他stackoveflow问题,我仍然没有更聪明.我现在正在构建的应用程序是rails 3.1应用程序,我正在使用设计1.5.1
以下是它们有用的相关路线
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"users/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"users/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"users/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"users/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"users/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"users/registrations"}
Run Code Online (Sandbox Code Playgroud)
你registrations_controller.rb保存到哪里了?位置很重要。我发现我犯了一个错误,将其保存到app/controllers/devise/.. 它只需要保存在app/controllers/.例如:
app/controllers/registrations_controller.rb
此外,config/routes.rb路线应定义为:
devise_for :users, controllers: { registrations: 'registrations' }
| 归档时间: |
|
| 查看次数: |
12426 次 |
| 最近记录: |