ruby-on-rails - rails电子邮件激活页面添加电子邮件地址
问题描述
我用的是rails4.2.8和ruby2.5.0;
我有 email_confirm.html.erb ,当用户注册完成后,跳转到这个 html 页面,html 代码如下:
<% provide(:title, 'email activation') %>
<div class="container">
<div class="col-md-8 col-md-offset-2 col-xs-12 col-sm-12 bgCo pdlr">
<h3 class="pageItemTitle"><i class="fa fa-envelope text-yellow mr5"></i>email activation</h3>
<h4 class="pd10 bgCo">Please Activation account:</h4>
<div class="text-center">
<span class="text-gray pbt20 ">The email had send to : <span class="text-yellow fs18"><%= current_user.email %></span></span>
</div>
<a class="btn btn-default pull-right" href="###">Go to the mailbox to check</a>
</div>
</div>
关于注册的 user_controller.rb 如下:
def create
@user = User.new(user_params)
if @user.save
log_in @user
flash[:success] = "还差一步就注册成功了!"
redirect_to :email_confirm
else
flash.now[:danger] = '注册失败,请输入正确内容!'
render :new
end
结尾
我想得到邮箱公司对应的网址<%= current_user.email %>
,这样as xxx@gmail.com
对应mail.google.com
,把邮箱公司的url添加到<a class="btn btn-default pull-right" href="###">Go to the mailbox to check</a>
我已经完成了逻辑内容,例如:
s = "dafaaf@gmail.com"
tumple = ["mail.qq.com","mail.126.com","mail.163.com","www.yeah.net","mail.sina.com.cn","mail.yahoo.com","mail.sohu.com","mail.aliyun.com","mail.google.com"]
y = s[/([A-Za-z0-9]+)(@)(.*+)/,3]
tumple.each_index do |i|
if tumple[i].include?y
print(tumple[i])
else if y==="gmail.com"
print("mail.google.com")
end
break
end
end
但是现在,我怎样才能将这个逻辑内容添加到 rails(或控制器)?
请帮助我,非常感谢!
解决方案
假设您在页面中有current_user
对象。email_confirm.html.erb
在该对象中,您收到了用户的电子邮件。在这种情况下,您可以将邮箱代码复制到application_helper
在application_helper.rb文件中:
def get_mailbox(email)
email = email.split('@').last
tumple = ["mail.qq.com","mail.126.com","mail.163.com","www.yeah.net","mail.sina.com.cn","mail.yahoo.com","mail.sohu.com","mail.aliyun.com","mail.google.com"]
if email == "gmail.com"
return "mail.google.com"
else
tumple.find { |t| return t if t.include? email }
end
end
现在,在视图文件email_confirm.html.erb
<a class="btn btn-default pull-right" href="<%= get_mailbox(current_user.email) %>">Go to the mailbox to check</a>
希望能帮助到你!
注意我不检查你的逻辑,我也假设你有一个 current_user 对象。
推荐阅读
- vbscript - VBScript:从网页下载 JSON 文件并将内容读取到变量
- ios - 如何从 AVAudioBuffer 音频样本中确定音量
- next.js - NextJs - Apollo - 第一次渲染不是 SSR
- sql - 没有 CREATE TABLE 的连接列上的 SQL JOIN
- sqlite - 当从文字中的相同总数中减去总和时,SQLite 会显示浮点数
- python - 在熊猫数据框中组合多行
- reactjs - 收到警告:列表中的每个孩子都应该有一个唯一的“关键”道具。在传播 props 和组合多个 Mui 组件时
- spring-integration - WARN JdbcChannelMessageStore 带有 id 的消息没有被删除
- python - cv2.imshow([winname], [mat]) 后的分段错误
- angular - AngularFirestore 动态查询