ruby-on-rails - 将 url 添加到字符串
问题描述
在我的应用程序中,我希望能够根据用户偏好通过电子邮件或短信发送确认消息。在这些消息中,有一个链接供他们单击以确认。
对于电子邮件,我在视图中添加了这样的内容:
<%= link_to "Click here to confirm", confirmation_url(param stuff) %>
但是,我不确定如何对短信做同样的事情。我正在使用 twilio-ruby gem,我只有一个可以发送消息的字符串。像这样的东西不起作用:
client = Twilio::REST::Client.new
client.messages.create({
from: ENV['TWILIO_PHONE_NUMBER'],
to: phone_number,
body: "Welcome to MySite. Please click this link to confirm: #{ confirmation_url(param stuff) }
})
基本上我了解 link_to 如何获取 URL,但如果我不在 html 视图上下文中,我不知道该怎么做。
感谢任何帮助!
解决方案
您可以使用
Rails.application.routes.url_helpers.confirmation_url(param stuff)
推荐阅读
- excel - 在Excel中计算开始日期之前和结束日期之后的行
- c++ - Stroustroup: free(): 实现 vector::reserve() 时在 tcache 2 中检测到双重空闲
- jquery - 在 Wordpress 中使用 wp_editor 插入 TinyMce 框时出现 toggleClass 错误
- apache-spark - Databricks 和 Power BI 中的增量表
- python - Python appending dataframe to exsiting excel file and sheet
- c - 我们总是必须在 C 中分配函数的返回值吗?
- jquery - Jquery 在悬停时加载 MVC 视图会导致闪烁问题
- vhdl - VHDL - 为什么在“进程”块中不包含其他条件是不好的做法?
- google-cloud-platform - 增加完全托管 Cloud Run 中使用的 google 托管证书的过期时间
- c - 为什么这个程序没有输出?