Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make rails link as bootstrap button

I have anchor links in rails like this.

<%= link_to 'Edit', edit_product_path(@product) %> |
<%= link_to 'Back', products_path %>

I want to have them as a button and I want to use bootstrap button.

Here's how I am trying to achieve it.

<div class="btn btn-primary">
  <%= link_to 'Edit', edit_product_path(@product) :class => "btn" %> |
  <%= link_to 'Back', products_path :class => "btn"%>
</div>

But this is not working for some reason.

What's wrong here?

like image 787
Suraj Avatar asked Jan 08 '16 07:01

Suraj


2 Answers

You forgot the comma after the path:

<div class="btn btn-primary">
  <%= link_to 'Edit', edit_product_path(@product), :class => "btn" %> |
  <%= link_to 'Back', products_path, :class => "btn"%>
</div>
like image 116
taglia Avatar answered Oct 27 '22 01:10

taglia


Other than the comma is missing, it would be better to remove or modify the class attribute in the div tag to something more sensible it as this would create an unnecessary duplicate of buttons inside one another. It should look something like this:

<div> <%= link_to 'Edit', edit_product_path(@product), :class => "btn btn-primary" %> | <%= link_to 'Back', products_path, :class => "btn"%> </div>

like image 38
Ahmed El Bakry Avatar answered Oct 27 '22 01:10

Ahmed El Bakry