Rails 6.1 now
supports
rendering SMS links.
We can use the recently added sms_to
rendering SMS anchor links.
This SMS anchor link when clicked pops open user’s SMS client targetting the specified phone number.
Using sms_to
Here are a few ways you can use the sms_to
helper in your Rails views:
We can just pass the phone number. In this case, the phone number is also used as the name of the link.
ERB code:
Rendered HTML:
We can explicitly specify the name of the link.
ERB code:
Rendered HTML:
We can specify the content of the SMS body.
ERB code:
Rendered HTML:
We can also pass a block to the sms_to
helper if we want more control over the content of the rendered SMS anchor tag:
ERB code:
Rendered HTML: