2015-09-01 2 views
0

Я новичок в Rails. Я использую Devise для добавления аутентификации и подтверждения по электронной почте при регистрации. Когда я запускаю код на своем локальном, я получаю сообщение об ошибке в заголовке. Я просмотрел похожие сообщения и попробовал запустить rake db:reset и перезапустить сервер.NoMethodError in Devise :: RegistrationsController # create undefined method `confirm_sent_at = 'для # <Пользователь: 0x007fd83f5ccb68>

Я добавил :confirmable в models/user.rb

class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable end

Сообщение об ошибке выделяет этот блок кода и конкретно взывает строку кода, начиная с match ? в строке 433

else match = match_attribute_method?(method.to_s) match ? attribute_missing(match, *args, &block) : super end end

Completed 500 Internal Server Error in 327ms (ActiveRecord: 0.5ms) 

NoMethodError (undefined method `confirmation_sent_at=' for # <User:0x007fd21e2ebce0>): 
activemodel (4.2.3) lib/active_model/attribute_methods.rb:433:in `method_missing' 
devise (3.5.2) lib/devise/models/confirmable.rb:240:in `generate_confirmation_token' 
activesupport (4.2.3) lib/active_support/callbacks.rb:430:in `block in make_lambda' 
activesupport (4.2.3) lib/active_support/callbacks.rb:143:in `call' 

Я ценю любую помощь!


Добавлена ​​миграция файлов

class DeviseCreateUsers < ActiveRecord::Migration 
    def change 
    create_table(:users) do |t| 
     ## Database authenticatable 
     t.string :name 
     t.string :email,    null: false, default: "" 
     t.string :encrypted_password, null: false, default: "" 

     ## Recoverable 
     t.string :reset_password_token 
     t.datetime :reset_password_sent_at 

     ## Rememberable 
     t.datetime :remember_created_at 

     ## Trackable 
     t.integer :sign_in_count, default: 0, null: false 
     t.datetime :current_sign_in_at 
     t.datetime :last_sign_in_at 
     t.string :current_sign_in_ip 
     t.string :last_sign_in_ip 

     ## Confirmable 
     t.string :confirmation_token 
     t.datetime :confirmed_at 
     t.datetime :confirmation_tokention_sent_at 
     t.string :unconfirmed_email # Only if using reconfirmable 

     ## Lockable 
     # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 
     # t.string :unlock_token # Only if unlock strategy is :email or :both 
     # t.datetime :locked_at 

     t.timestamps null: false 
    end 

    add_index :users, :email,    unique: true 
    add_index :users, :reset_password_token, unique: true 
    # add_index :users, :confirmation_token, unique: true 
    # add_index :users, :unlock_token,   unique: true 
    end 
end 
+0

Можете ли вы опубликовать миграцию, где вы добавили подтверждения? – trh

+2

В вашей миграции есть опечатка - не должно 'confirm_tokention_sent_at' быть' confirm_sent_at'? –

+0

hmm .. логически, что имеет смысл для меня. Я скажу, что все, что я сделал, было раскомментировано этими четырьмя строками кода для ': confirmable'. Я попробовал 't.datetime: confirm_sent_at' и по-прежнему получаю ту же ошибку. – leo

ответ

0

@Wand Maker был правильным. Код должен отражать confirmation_sent_at вместо confirmation_tokention_sent_at.

Дополнительный шаг, который я должен был принять в том, чтобы удалить мой schema.rb файл, запустите rake db:reset, а затем rake db:migrate создать обновленный (и правильно) schema.rb.

Смежные вопросы