Reputation: 397
In my app, I want to be able to send confirmation messages via email or text message depending on user preference. In those messages, there's a link for them to click to confirm.
For the emails, I put something like this in the view:
<%= link_to "Click here to confirm", confirmation_url(param stuff) %>
However, I'm not sure how to do the same thing for the text messages. I'm using the twilio-ruby gem, and I only have a string I can send for the message. Something like this doesn't work:
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) }
})
Basically I understand how link_to works to get the URL, but I'm not sure how to do it if I'm not in an html view context.
Appreciate any help!
Upvotes: 0
Views: 57
Reputation: 5313
You can use
Rails.application.routes.url_helpers.confirmation_url(param stuff)
Upvotes: 1