我已经设计并设置了 CanCan,但我试图进入我的 rails 应用程序中的注册页面,但它会将我重定向到主页,说我无权访问此页面。
我有一个自定义注册控制器:
class Devise::RegistrationsController < DeviseController
before_filter :check_permissions, :only => [:new, :create, :cancel]
skip_before_filter :require_no_authentication
def check_permissions
authorize! :create, resource
end
def edit
@user = User.find(current_user.id)
@profile = Profile.new
end
def update
# required for settings form to submit when password is left blank
if params[:user][:password].blank? && params[:user][:password_confirmation].blank?
params[:user].delete(:password)
params[:user].delete(:password_confirmation)
end
@user = User.find(current_user.id)
if @user.update_attributes(params[:user])
set_flash_message :notice, :updated
# Sign in the user bypassing validation in case his password changed
sign_in @user, :bypass => true
redirect_to after_update_path_for(@user)
else
render "edit"
end
end
protected
def after_update_path_for(resource)
user_path(resource)
end
private
end
它与此有关,before_filter :check_permissions,...
因为当我删除此行时,我收到一条错误消息
undefined method `user_registration_path'
从我的“设计/注册#new”中的注册表单:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
如何修复我的注册表单?
另外,这是我的路线:
devise_for :user, :controllers => { :registrations => "registrations" }, :skip => [:registrations, :sessions] do
get 'signup' => 'devise/registrations#new', :as => :new_user_registration
end