在注册新用户后,我会被重定向到登录页面,其中包含以下flash[:alert]
消息:
“您需要先登录或注册 继续“。
我的用户模型使用Devise的:confirmable
模块,因此如果在注册后用户会看到修改后的消息,那就太好了:
“感谢您注册。我们已向您发送了确认电子邮件。请查看您的电子邮件”
有没有办法实现它?
关于设计工作流程的说明:
目前,用户不知道已向他发送了确认电子邮件。只有当他尝试使用未经证实的电子邮件地址登录时,他才会看到Devise的失败消息:
“您必须在继续之前确认您的电子邮件地址。”
我只是按照前两步:
1)创建RegistrationsController:
class RegistrationsController < Devise::RegistrationsController
protected
# TODO: will this method be triggered one day?
def after_sign_up_path_for(resource)
# '/an/example/path'
new_user_session_path
end
def after_inactive_sign_up_path_for(resource)
new_user_session_path
end
end
2)将路线更改为:
devise_for :users, :controllers => {:registrations => 'registrations'}
答案 0 :(得分:2)
首先,添加设计:确认您的models / user.rb
devise :confirmable
然后,执行迁移:
rails g migration add_confirmable_to_devise
将生成db / migrate / YYYYMMDDxxx_add_confirmable_to_devise.rb。添加以下内容以进行迁移。
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
User.all.update_all confirmed_at: Time.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
执行迁移rake db:migrate
如果不使用可重新配置,请更新config / initializers / devise.rb中的配置
config.reconfirmable = false
希望这会对你有所帮助。
答案 1 :(得分:0)
您需要将其添加到devise.en.yml
目录中的/config/locales/
文件中。在devise > registrations
下,添加signed_up_but_unconfirmed
并设置值
devise:
registrations:
signed_up_but_unconfirmed: "Thanks for signing up. We have sent you a confirmational email. Please check your email."
希望这有帮助!