Quantico
Quantico

Reputation: 2436

link_to with image, text and css in rails

I am trying to create a btn (using css) that will have both an image and a text. I have the following code that works without the class, but when I am adding the class my code breaks. Is there a way to combine all of the above in link_to?

<%= link_to new_task_path do %>
   <%= image_tag("new.png"), :class => 'btn btn-info' %> New Task 
<% end %>

Upvotes: 0

Views: 285

Answers (2)

Quantico
Quantico

Reputation: 2436

Solved with

<%= link_to image_tag("new.png") + "New Task" , new_task_path , :class => 'icon btn' %>

Upvotes: 1

simanchala
simanchala

Reputation: 127

add the class on tag(anchor tag)

<%= link_to new_task_path, :class => 'btn btn-info' do %>
   <%= image_tag("new.png") %> New Task 
<% end %>

Upvotes: 0

Related Questions