Ruby on rails rails电子邮件激活页面添加电子邮件地址

Ruby on rails rails电子邮件激活页面添加电子邮件地址,ruby-on-rails,Ruby On Rails,我使用了rails4.2.8和ruby2.5.0 我有电子邮件_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 cla

我使用了rails4.2.8和ruby2.5.0


我有电子邮件_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>
结束

我想得到邮箱公司对应的
网站,比如
xxx@gmail.com
对应
mail.google.com
,并将邮箱公司的url添加到

我已完成逻辑内容,如:

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(或控制器)?

请帮帮我,非常感谢

假设您在
email\u confirm.html.erb
页面中有
当前用户
对象。在该对象中,您获得了用户的电子邮件。在这种情况下,您可以将邮箱代码复制到
application\u helper

应用程序\u 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
现在,在查看文件中,通过电子邮件_confirm.html.erb

<a class="btn btn-default pull-right" href="<%= get_mailbox(current_user.email) %>">Go to the mailbox to check</a>

希望有帮助


N.B.我没有检查您的逻辑,而且我假设您有一个当前用户对象。

您确实应该以更好的ruby方式重构您的逻辑

def get_mailbox
  email = current_user.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"
    print "mail.google.com"
  else
    tumple.find { |t| print t if t.include? email }
  end
end

您是否在
电子邮件_confirm.html.erb
页面中获得了
?我收到了电子邮件_confirm.html.erb,当用户注册完成后,它会跳转到此html页面,html代码如下:“->请提供使此
跳转的代码片段,并描述此代码的位置placed@Emu对电子邮件内容正确。@AntonTkachov谢谢,我在问题中添加了用户\u controller.rb相关代码。谢谢@Emu,我尝试过作为您的代码,但似乎
href=“
无法获取电子邮件公司的网站,它什么也得不到…@sylor_huang,因为您的方法实际上没有返回任何内容。您需要更改代码。目前,它只是打印,没有返回。@Emu非常感谢,您的意思是我应该将
def get_邮箱
print
更改为
return
?我已经更改了它,但是我无法在
email\u cofirm.html.erb
中获取url。url显示为“无”…您可以使用sovalina在另一个答案中给出的代码以及返回值来更改帮助器代码。希望它能工作@Emu抱歉,我不明白,我是rails的初学者,如果你有时间,你能帮我写代码吗非常感谢~~谢谢你的回答,我怎样才能得到
get\u mailbox()
结果
email\u confirm.html.erb
,这就是我如何在
href
中写代码的方法
def get_mailbox
  email = current_user.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"
    print "mail.google.com"
  else
    tumple.find { |t| print t if t.include? email }
  end
end