2011-07-27 3 views
0

내가시나 : 세션

모든 내가 로그인 할 때를 제외하고 작동 (https://github.com/ehsanul/Sinatra-Authlogic-Template 다음) 내가 Authlogic와 통합하고 작은시나 응용 프로그램을 쓰고 있어요와 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? 방식에 실패했다. 내가 (때문에 다른 시스템과 데이터 무결성에) 테이블에이 열을 추가 할 수없는 생각 때문에 나는 단지이 사람을 도움이

내 User.rb

class UserSession < Authlogic::Session::Base 
end 

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

    end 

    def active? 
    return true 
    end 
end 

희망 return true 내 방법을 말했다!