0

현재 확인 메일을 확인 인증과 통합하려고합니다. 나는 명령의 유증 문서에서 다음 :Rails Devise confirmable error

https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users

나는 다음과 같은 오류 얻을 새 사용자 등록을 시도 :

NameError in Devise::RegistrationsController#create 
undefined local variable or method `confirmed_at' for #<User:0x9b87b38> 

User.rb

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 



    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable, :confirmable 
end 

레일 이동하기 add_confirmable_to_devise

class AddConfirmableToDevise < ActiveRecord::Migration 
    # Note: You can't use change, as User.update_all will fail in the down migration 
    def up 
    add_column :users, :confirmation_token, :string 
    add_column :users, :confirmed_at, :datetime 
    add_column :users, :confirmation_sent_at, :datetime 
    # add_column :users, :unconfirmed_email, :string # Only if using reconfirmable 
    add_index :users, :confirmation_token, unique: true 
    # User.reset_column_information # Need for some types of updates, but not for update_all. 
    # To avoid a short time window between running the migration and updating all existing 
    # users as confirmed, do the following 
    execute("UPDATE users SET confirmed_at = NOW()") 
    # All existing user accounts should be able to log in after this. 
    # Remind: Rails using SQLite as default. And SQLite has no such function :NOW. 
    # Use :date('now') instead of :NOW when using SQLite. 
    # => execute("UPDATE users SET confirmed_at = date('now')") 
    # Or => User.all.update_all confirmed_at: Time.now 
    end 

    def down 
    remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at 
    # remove_columns :users, :unconfirmed_email # Only if using reconfirmable 
    end 
end 

confirmations_controller.rb

class ConfirmationsController < Devise::ConfirmationsController 
    private 
    def after_confirmation_path_for(resource_name, resource) 
    your_new_after_confirmation_path 
    end 
end 

routes.rb

Rails.application.routes.draw do 
    devise_for :users, controllers:{ confirmations: 'confirmations'} 
    resources :videos 
    get 'welcome/index' 

    get 'welcome/new' 

    root 'welcome#index' 



end 

나는 또한 내가 내 Gemfile에 'simple_token_authentication을 보석을 추가하고 실행해야 말하는 사람을 보았다

rails g migration add_authentication_token_to_users authentication_token:string:index 
rake db:migrate 

그러나 그 문제는 해결되지 않았습니다.

아이디어가 있으십니까? 감사!

+0

'db/schema.rb' 파일에서'users '테이블에'confirmed_at' 컬럼이 있는지 확인하십시오. – chumakoff

답변

0

데이터베이스의 각 열에 대해 ActiveRecord는 클래스의 열을 따라 이름이 지정된 특성 (데이터베이스에 표시된 열로 클래스에 대한 특성)을 "설정"및 "가져 오기"하는 메서드를 만듭니다. 이 경우 클래스는 사용자이고 열은 confirmed_at입니다.

오류 메시지가 사용자 클래스에 메서드가 없다는 것을 알려줍니다. User.methods를 호출하여 메서드를 볼 수 있습니다.

최신 schema.rb 파일을 보지 않고도 Devise 확인 가능한 마이그레이션이 누락되었다고 가정합니다.

새 마이그레이션 파일을 만들려면 rails g migration AddConfirmableToUsers; DB/마이그레이션 머리 및 이것을 붙여 복사 후 해당 이전 파일을 열고 :

class AddConfirmableToUsers < ActiveRecord::Migration def change change_table(:users) do |t| # Confirmable t.string :confirmation_token t.datetime :confirmed_at t.datetime :confirmation_sent_at t.string :unconfirmed_email # Only if using reconfirmable end add_index :users, :confirmation_token, :unique => true end end

다음 rake db:migrate를 호출한다.

+0

감사! 그게 문제 였어! 마침내 이메일을 보내려면해야 할 일이 있습니까? 왜냐하면 지금은 마침내 다시 가입 할 수 있지만 확인 이메일이 전송되지 않았기 때문입니다. – Prometheus

+0

별로 많지는 않지만 악마가 세부 사항에 있습니다. 나는 mailcatcher.me가 개발중인 메일을 "보내"(개인 선호, 나중에 "보내기"를 인용하는 이유를 이해할 것입니다.) 다음과 같이 읽습니다 : https://richonrails.com/articles/ debugging-emails-with-mailcatcher –

+0

나는 그것을 조사 할 것이다. 많은 도움을 주셔서 감사합니다! – Prometheus