Devise::RegistrationsController#create 中的 NameError:未定义的局部变量或方法 `confirmed_at`
NameError in Devise::RegistrationsController#create: undefined local variable or method `confirmed_at`
在此处输入图片描述我是 rails 的新手,我正在尝试设计为用户获取验证电子邮件
# 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
我得到的错误是
undefined local variable or method `confirmed_at' for # Did you mean? confirmed?
the github repo is https://github.com/dinesh124/roughmart
你的列实际上并不存在于数据库中,因为你的迁移没有工作。
从迁移中删除 def change
,它将覆盖 up/down
。
或者,在 change
方法中添加列并删除 up/down
。
您需要的列不在数据库中。
您应该删除迁移中的更改方法。但是您不能更改迁移并再次 运行 它。不会 运行.
您应该回滚迁移,编辑迁移文件并再次运行。
检查这个解释问题的答案:
在此处输入图片描述我是 rails 的新手,我正在尝试设计为用户获取验证电子邮件
# 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
我得到的错误是
undefined local variable or method `confirmed_at' for # Did you mean? confirmed? the github repo is https://github.com/dinesh124/roughmart
你的列实际上并不存在于数据库中,因为你的迁移没有工作。
从迁移中删除 def change
,它将覆盖 up/down
。
或者,在 change
方法中添加列并删除 up/down
。
您需要的列不在数据库中。
您应该删除迁移中的更改方法。但是您不能更改迁移并再次 运行 它。不会 运行.
您应该回滚迁移,编辑迁移文件并再次运行。
检查这个解释问题的答案: