2011-07-27 36 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 

希望这可以帮助别人!