-1

enter image description hereI'm new to rails and I'm trying devise to get an authentication email for users

# user.rb:          
class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
  :recoverable, :rememberable, :trackable,                                                      
  :validatable, :confirmable
end

# development.rb       
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { host: ENV['MAIL_HOST'] }  
config.action_mailer.delivery_method = :smtp      
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: ENV['MAIL_HOST'],
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"] 
}
config.action_mailer.default_url_options = {:host => "localhost:3000"}

class AddConfirmableToDevise < ActiveRecord::Migration[5.2]
  def change
  end

  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
    User.update_all(:confirmed_at => Time.now)
    # All existing user accounts should be able to log in after this.
  end

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

The error I'm getting is

undefined local variable or method `confirmed_at' for # Did you mean? confirmed? the github repo is https://github.com/dinesh124/roughmart

rocky
  • 45
  • 8

2 Answers2

1

Your columns don't actually exist in the database because your migrate isn't working.

Remove def change from your migrate, it overrides up/down.

Or, add the columns in the change method and remove up/down.

Matt
  • 13,948
  • 6
  • 44
  • 68
0

The column you need is not in the database.

You should remove the change method in the migration. But you cannot change a migration and run it again. It won’t run.

You should roll back the migration, edit the migration file and run it again.

Check this answer explaining the problem: https://stackoverflow.com/a/10767930/3372172

Pablo
  • 3,004
  • 1
  • 12
  • 19
  • yes !!!thank you!!!!.it helped but im still is getting another error :535 Authentication failed: Bad username / password . and a no method error after defining the environmental variables. – rocky Jan 31 '19 at 17:12