gpt4 book ai didi

ruby-on-rails - devise.en.yml 文件中的变量

转载 作者:行者123 更新时间:2023-12-04 04:37:39 26 4
gpt4 key购买 nike

我想在设计确认消息中添加用户的电子邮件地址,现在在发送确认邮件后,设计显示我 “一封带有确认链接的消息已发送到您的电子邮件地址。请打开链接以激活您的帐户。” 但我想要的是插入已注册用户的电子邮件,因此它应该类似于 “带有确认链接的消息已发送到您的 #{params[:user][:email]}。请打开链接以激活您的帐户。”

但它不显示电子邮件,而是只显示文本。任何建议如何做到这一点?

最佳答案

今天解决了这个问题,所以思想也应该为其他人发布答案。必须使用以下代码覆盖设计注册 Controller 创建操作:

class RegistrationsController < Devise::RegistrationsController 
# POST /resource
def create
build_resource(sign_up_params)
if resource.save
# this block will be used when user is saved in database
if resource.active_for_authentication?
# this block will be used when user is active or not required to be confirmed
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
# this block will be used when user is required to be confirmed
user_flash_msg if is_navigational_format? #created a custom method to set flash message
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
# this block is used when validation fails
clean_up_passwords resource
respond_with resource
end
end

private

# set custom flash message for unconfirmed user
def user_flash_msg
if resource.inactive_message == :unconfirmed
#check for inactive_message and pass email variable to devise locals message
set_flash_message :notice, :"signed_up_but_unconfirmed", email: resource.email
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}"
end
end
end

然后在 devise.en.yml 文件中进行必要的更改,我们都设置好了
en:
devise:
registrations:
signed_up_but_unconfirmed: "A confirmation link has been sent to %{email}. Click the link to activate your account."

P.S 查看评论了解正在发生的事情

关于ruby-on-rails - devise.en.yml 文件中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19452075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com