August 19

0 comments

A quick way to have a link_to show as a button instead of a text link

By Christopher Mendla

August 19, 2016


Last Updated on November 30, 2019 by Christopher G Mendla

link_to can be modified to show a button instead of a text link. The trick is to enclose the link/button text in a button tag and add .html_safe .

<%= link_to ““.html_safe, ‘http://blog.chrismendlatech.com’, target:’_blank’, class: ‘button’%>

<%= link_to "< button>My Blog< /button>".html_safe, 'http://blog.chrismendlatech.com', target:'_blank', class: 'button'%>

Since there is no user input here, html_safe should be safe to use. However, you need to decide for yourself on a case by case basis.

Christopher Mendla

About the author

Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}