2011-07-27 72 views
0

我寫的是我與Authlogic整合小西納特拉應用程序(以下https://github.com/ehsanul/Sinatra-Authlogic-Template西納特拉:DB認證與會話

一切正常,除了當我嘗試登錄。我收到以下錯誤:

NameError at /login 
undefined local variable or method `active' for #<User:0x000001040208f0> 

我包括authlogic gem與將其作爲供應商包括在內。所以我的Sinatra應用程序與Github上的應用程序不完全相同。

任何和所有的查詢將非常感謝!謝謝!

回答

1

發現我的問題。

下面是根據Github的頁面模型:

class User < ActiveRecord::Base 
    acts_as_authentic do |c| 
    # Bcrypt is recommended 
    #crypto_provider = Authlogic::CryptoProviders::BCrypt 
    c.perishable_token_valid_for(24*60*60) 
    c.validates_length_of_password_field_options = 
    {:on => :update, :minimum => 6, :if => :has_no_credentials?} 
    c.validates_length_of_password_confirmation_field_options = 
    {:on => :update, :minimum => 6, :if => :has_no_credentials?} 
    end 

    def active? 
    active 
    end 

    def has_no_credentials? 
    crypted_password.blank? #&& self.openid_identifier.blank? 
    end 

    def send_activation_email 
    Pony.mail(
     :to => self.email, 
     :from => "[email protected]", 
     :subject => "Activate your account", 
     :body => "You can activate your account at this link: " + 
       "http://domain.tld/activate/#{self.perishable_token}" 
    ) 
    end 

    def send_password_reset_email 
    Pony.mail(
     :to => self.email, 
     :from => "[email protected]", 
     :subject => "Reset your password", 
     :body => "We have recieved a request to reset your password. " + 
       "If you did not send this request, then please ignore this email.\n\n" + 
       "If you did send the request, you may reset your password using the following link: " + 
       "http://domain.tld/reset-password/#{self.perishable_token}" 
    ) 
    end 
end 

我刪除了所有的郵件的方法,但我的劇本是失敗的active?方法,因爲它一直在尋找的用戶表中的活動列。因爲我無法此列追加到表(由於與其他系統數據的完整性),我只是告訴我的方法return true

我User.rb

class UserSession < Authlogic::Session::Base 
end 

class User < ActiveRecord::Base 
    acts_as_authentic do |c| 

    end 

    def active? 
    return true 
    end 
end 

希望這可以幫助別人!