2013-01-11 37 views
0

我目前正在設置一個基於tutorial on Devise labeled Email only signup的項目,並且似乎遇到了一個我無法解決的特定錯誤。我已經得到插件來執行除第3步以外的任何操作,它無法找到我添加的名爲confirm的自定義方法。我已經告訴設計使用在Devise和Rails中創建電子郵件註冊時出現問題

devise_for :users, :controllers => {:confirmations => 'confirmations'} 

爲我的用戶插件,但它忽略了我的控制器。

我有一個控制器稱爲confirmations_controller.rb,它包含以下代碼:

class ConfirmationsController < Devise::ConfirmationsController 
    def show 
    self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token]) 
    super if resource.confirmed? 
    end 

    def confirm 
    self.resource = resource_class.find_by_confirmation_token(params[resource_name][:confirmation_token]) 
    if resource.update_attributes(params[resource_name].except(:confirmation_token)) && resource.password_match? 
     self.resource = resource_class.confirm_by_token(params[resource_name][:confirmation_token]) 
     set_flash_message :notice, :confirmed 
     sign_in_and_redirect(resource_name, resource) 
    else 
     render :action => "show" 
    end 
end 

確切的錯誤是:

undefined method `confirmed?' for #<User:0x425f130> 

我使用軌道版本3.2.9,並制定2.2版本.1

我只是學習rails和ruby,所以我真的希望有人能幫助我。

+1

你加:可確定用戶類? –

回答

2

錯誤消息是關於confirmed?方法沒有定義。所添加的定製方法是confirm

confirmed?方法由confirmable module of device

加入作爲傑西在註釋中提到上述,使能對用戶類「可確認的」模塊。

示例用戶類:

class User < ActiveRecord::Base 
    devise ..., :confirmable, ... 

    ... 

end 
+1

謝謝,我確實想念這個,但是爲了徹底解決這個問題,我不得不按照這裏的指導來解決出現的下一個錯誤:https://github.com/plataformatec/devise/wiki/How-To: -Add-:可確定對用戶 – theother404

相關問題