Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make button a link to PDF file with Bootstrap

I'd like to link a pdf to a button using the bootstrap framework in Rails. For example the button would say download now and link to the PDF. I'm not concerned on how the PDF opens, just that it links to it.

In the Bootstrap documentation it says to use only the <a> tag and it doesn't mention anything about the <%= link_to %> tag. This is what's listed in the Bootstrap doc's <a class="btn btn-large btn-danger" href="#">Download Now</a>, where "Download Now" is the text show on the button.

Any help is appreciated.

like image 341
mcadamsjustin Avatar asked Mar 15 '26 01:03

mcadamsjustin


1 Answers

You can specify class as one of the arguments of link_to

<%= link_to "Download Now", '/path/to/file/or/path_method', :class => "btn btn-large btn-danger" %>

or

<%= link_to '/path/to/file/or/path_method', :class => "btn btn-large btn-danger" do %>
  Download Now
<% end %>

Rails Framework Documentation for link_to

like image 163
Bogdan Rybak Avatar answered Mar 18 '26 12:03

Bogdan Rybak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!