我想使用 Devise 在我的 rails 应用程序中添加电子邮件确认。我收到此错误消息:
“设计中的 NoMethodError::RegistrationsController#create undefined method `confirmation_instructions' for MailForm::Base:Class”
架构.rb
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "username"
t.string "first_name"
t.string "last_name"
t.float "latitude"
t.float "longitude"
t.boolean "admin", default: false
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
用户.rb
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :confirmable
end
路线.rb
Rails.application.routes.draw do
devise_for :users
resources :users do
member do
get :confirm_email
end
end
设计.rb
Devise.setup do |config|
config.mailer_sender = 'my_email@gmail.com'
#mail_form
config.mailer = 'MailForm::Base'
end
发展.rb
config.action_mailer.default_url_options = { host: "https://myapp.com" }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
authentication: 'plain',
enable_starttls_auto: true,
user_name: ENV['GMAIL_EMAIL'],
password: ENV['GMAIL_PASSWORD']
}
生产.rb
config.action_mailer_default_url_options = { host: 'https://myapp.com' }
Rails.application.routes.default_url_options[:host] = 'https://myapp.com'
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default charset: 'utf-8'
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
authentication: 'plain',
enable_starttls_auto: true,
user_name: ENV['GMAIL_EMAIL'],
password: ENV['GMAIL_PASSWORD']
}
这是因为联系表格的 mail_form gem 吗?我应该创建RegistrationController
吗?谁能猜出这里的主要问题?