0

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!

1 Answer 1

1

You can use

Rails.application.routes.url_helpers.confirmation_url(param stuff)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that worked perfectly! Just had to figure out how to set the default_url_options per environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.