2009-09-02 9 views
0

작년에 활약하고있는 환상적인 축구 리그 앱이 있는데 시즌이 시작되기 전에 다시 시도 할 시간입니다. 데이터베이스를 지우고 "rake db : migrate"를 수행하여 처음부터 다시 시작할 수있었습니다. 로그인 페이지가 잘 나타나지만 사용자가 내가 로그/production.log에 다음과 같은 오류 얻을 restful_authentication 사용 "가입"할 때 : 여기정의되지 않은 메소드 'make_activation_code'Restful_Authentication을 사용하는 레일 오류

NoMethodError (undefined method `make_activation_code' for #<User:0xb7743490>): 
/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:256:in `method_missing' 
/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:173:in `send' 
/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:173:in `evaluate_method' 
/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:161:in `call' 

을 내 user.rb 클래스의 일부 조각은 다음과 같습니다

내 user.rb의
require 'digest/sha1' 
require 'gravtastic' 

class User < ActiveRecord::Base 
    include Authentication 
    include Authentication::ByPassword 
    include Authentication::ByCookieToken 

# has_one :division 
has_and_belongs_to_many :divisions 

has_gravatar 

validates_presence_of  :login 
validates_length_of  :login, :within => 3..40 
validates_uniqueness_of :login, :case_sensitive => false 
validates_format_of  :login, :with => RE_LOGIN_OK, :message => MSG_LOGIN_BAD 

validates_presence_of  :team_name 
validates_length_of  :team_name, :within => 3..40 
validates_uniqueness_of :team_name, :case_sensitive => false 

# validates_format_of  :name,  :with => RE_NAME_OK, :message => MSG_NAME_BAD,  :allow_nil => true 
# validates_length_of  :name,  :maximum => 100 

validates_presence_of  :email 
validates_length_of  :email, :within => 6..100 #[email protected] 
validates_uniqueness_of :email, :case_sensitive => false 
validates_format_of  :email, :with => RE_EMAIL_OK, :message => MSG_EMAIL_BAD 

before_create :make_activation_code 

# HACK HACK HACK -- how to do attr_accessible from here? 
# prevents a user from submitting a crafted form that bypasses activation 
# anything else you want your user to change should be added here. 
attr_accessible :login, :email, :team_name, :password, :password_confirmation 

바닥 :

protected 

def make_activation_code 
    self.activation_code = self.class.make_token 
end 

def make_password_reset_code 
    self.reset_password_code = Digest::SHA1.hexdigest(Time.now.to_s.split(//).sort_by {rand}.join) 
end 

make_activation_code이 사용자 클래스에 정의하고 정의되지 않은 이유를 이해하지 않도록 activation_code가 이전에 만들어졌다.

답변

0

좋아요. 제 질문에 대한 답변을 찾았습니다. before_create를 다음과 같이 바꿔야했습니다.

def before_create 
    self.activation_code = self.class.make_token 
    end 

    def make_password_reset_code 
    self.reset_password_code = Digest::SHA1.hexdigest(Time.now.to_s.split(//).sort_by {rand}.join) 
    end 

레일스의 내부 변경이 있었어야합니다.

0

이 문제를 직접 해결하는 방법을 말할 수는 없지만 비정상적인 동작이있는 상황에서는 일반적으로 문제의 원인을 찾아내는 것이 좋습니다. 귀하의 경우, 나는 "make_activation_code"와 다른 이름의 메소드를 작성하는 것과 같은 것을 시도 할 것입니다. before_create에 추가 할 수 있는지 알아보고 호출됩니다. 그렇다면 메소드 안에 현재 make_activation_code에있는 코드를 추가하고 여전히 작동하는지 확인하십시오.

이 특정 문제에 가장 가까운 현상은 플러그인 자체에 응용 프로그램 내부에서 사용자 모델을 재정의 할 수있는 사용자 모델이있는 새비지 비스트 플러그인입니다. 그래서 before_create에 다른 메서드를 추가하고 호출되는지 확인하면 User 모델 자체가 다른 부분에 정의 된 불량 사용자 모델로 대체되지 않는지 확인할 수 있습니다. 앱의

이 이론을 테스트하는 또 다른 방법은 개발 모드에서와 다른 방식으로 작동하는지 확인하는 것입니다. 프로덕션에서는 모델이 요청 사이에서 다시로드되지 않으므로 초기 환경로드 후에 다른 모델을 대체하는 플러그인에서 한 모델/메소드에 문제가 발생할 가능성이 적습니다.

0

보호 된 라인을 주석 처리하지 않으셨습니까?

관련 문제