David Geismar
David Geismar

Reputation: 3412

Adding specific class to image_tag within link_to in rails

I wanted to add an image with text inside my link_to so I wrote this piece of code that is working fine :

<%=link_to image_tag('fleche_droite.svg') + "Ajouter un joueur à la liste", invite_player_path(@tournament), class: "btn btn-success", id: "convocation-submit" %>

the problem is that I need to add a specific class to my image to give it the right size. How can I do that within the rails helper ?

Upvotes: 1

Views: 1666

Answers (2)

Nermin
Nermin

Reputation: 6100

Use block to define content of your link, inside block add image_tag with class

<%=link_to invite_player_path(@tournament), class: "btn btn-success", id: "convocation-submit" do %>
   <%= image_tag('fleche_droite.svg', class: 'your-class-name') %>
<% end %>

See also link_to helper

Upvotes: 3

Piotr Kruczek
Piotr Kruczek

Reputation: 2390

Try this:

<%=link_to image_tag('fleche_droite.svg', class: 'my_class') + "Ajouter un joueur à la liste", invite_player_path(@tournament), class: "btn btn-success", id: "convocation-submit" %>

Upvotes: 1

Related Questions