У меня есть приложение фэнтезийной футбольной лиги, которое работало в прошлом году, и пришло время снова начать его до начала сезона. Я очистил базу данных и сделал «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 определяются в классе User и код_активация была создана в миграции, так что я не понимаю, почему это не определенно.