2012-05-26 34 views
1

其实我用巫术进行认证与以下设置:
找不到用户使用id = pJycxPPmoBQw9D2mfW6W

  • 轨3.2.3
  • 的PostgreSQL 9.1.3
  • 康康舞

当我点击激活链接我得到以下错误的:

ActiveRecord::RecordNotFound in UsersController#activate 

Couldn't find User with id=pJycxPPmoBQw9D2mfW6W 

users_controllers.rb

#cancan

before_filter :require_login, :except => [:not_authenticated, :new, :create, :activate] 
load_and_authorize_resource 
skip_authorization_check :only => [:new, :create, :activate] 
skip_authorize_resource :only => [:new, :create, :activate] 

#activate方法

def activate 
    if (@user = User.load_from_activation_token(params[:id])) 
     @user.activate! 
     redirect_to(login_path, :notice => 'Your account is activated.') 
    else 
     not_authenticated 
    end 
    end 

生成令牌

def generate_token(column) 
    begin 
     self[column] = SecureRandom.urlsafe_base64 
    end while User.exists?(column => self[column]) 
end 

load_from_activation_token巫术源代码

def load_from_activation_token(token) 
    token_attr_name = @sorcery_config.activation_token_attribute_name 
    token_expiration_date_attr = @sorcery_config.activation_token_expires_at_attribute_name 
    load_from_token(token, token_attr_name, token_expiration_date_attr) 
end 

我能有一些帮助吗?

+0

显然,你在'#activate'中有错误。但是由于我们没有看到它的代码,我们无法帮助你。 –

+0

刚刚添加#activate方法 – blawzoo

+0

也添加其他相关方法。 –

回答

2

啊哈,我认为这个问题是在这里:

load_and_authorize_resource 

显然,对于params[:id]要求#activate不是用户ID,但令牌。 Cancan试图加载用户,并且(预计)失败。您也需要跳过加载此操作(与您已经跳过授权的方式类似)。

skip_load_and_authorize_resource :only => [:new, :create, :activate] 
+0

中加入了Whoa !!!!!!!!!塞尔吉奥你的男人。你的解决方案刚刚工作谢谢很多人 – blawzoo

+0

不客气:) –