2009-09-02 34 views
0

我有一个幻想足球联盟Rails应用程序去年工作,现在是时候让它在赛季开始之前再次开始。我清理了数据库并执行了“rake db:migrate”,因此我可以从头开始重新启动应用程序。登录页面出现罚款,但是当用户试图“注册”使用restful_authentication我得到的日志/ production.log以下错误:未定义的方法'make_activation_code'Rails错误使用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类中的一些片段:

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 

下我user.rb的:

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 

一定是在Rails内部的变化。

0

我不能说如何直接解决这个问题,但在出现异常行为的情况下,我的方法通常是试图找出导致问题的原因。在你的情况下,我会尝试诸如创建一个名称不同于“make_activation_code”的方法,看看你是否可以将它添加到before_create中并且它被调用。如果是这样,请将当前在make_activation_code中的代码添加到方法中,并查看它是否仍然有效。

我看到这个特定问题最接近的现象是Savage Beast插件,插件本身有一个用户模型,可以在应用程序内重新定义用户模型。这就是为什么看看你是否可以在你的before_create中添加一个不同的方法并查看它是否被调用会是很有趣的,所以你可以验证你的User模型本身不是被某个其他部分定义的流氓用户模型替代的应用程序。

测试此理论的另一种方法是查看它在生产中是否与开发模式不同。在生产中,模型不会在请求之间重新加载,所以在初始环境加载后,插件中的一个模型/方法覆盖另一个模型/方法的可能性较小。

0

您是否尝试过对保护线进行评论?