2009-09-02 7 views
0

私は昨年働いていたファンタジーのサッカーリーグレールアプリを持っていましたが、今シーズンが始まる前に再びそれを得る時間です。私はデータベースをクリアし、 "rake db:migrate"を実行したので、最初からアプリを再起動することができました。ログインページは罰金アップしますが、ユーザーは、私は、ログ/ production.logに次のエラーを取得するrestful_authenticationを使用して「サインアップ」しようとするとき:未定義のメソッド 'make_activation_code' Restful_Authenticationを使用したRailsエラー

:ここ

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は、Userクラスに定義され、それが定義されていない理由を私は理解していないので、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 

Railsの内部的な変更が行われていなければなりません。

0

私はこの問題を直接解決する方法を話すことはできませんでしたが、異常な動作がある状況では、通常、問題の原因を特定しようとしています。あなたの場合、私は "make_activation_code"とは違う名前のメソッドを作成するようなことをしようと思っています。それをbefore_createに追加して呼び出すことができるかどうかを見てください。その場合は、メソッド内に現在make_activation_codeにあるコードを追加し、それがまだ機能するかどうかを確認します。

この特定の問題に最も近い現象は、プラグイン自体がアプリケーション内のユーザーモデルを再定義できるユーザーモデルを持つSavage Beastプラグインにあります。そのため、before_createに別のメソッドを追加して呼び出されたかどうかを確認できるので、Userモデル自体が何らかの他の部分で定義された不正なUserモデルに置き換えられていないことを確認できます。あなたのアプリの

この理論をテストするもう1つの方法は、開発モードとは異なる方法で動作するかどうかを確認することです。プロダクションでは、モデルはリクエスト間でリロードされないため、初期環境負荷の後で、プラグイン内のあるモデル/メソッドで問題が発生する可能性は低くなります。

0

保護された行をコメントアウトしてみましたか?

関連する問題