2012-03-07 14 views
6

dodałem zdjęcie wewnątrz link_to pomocnika:Umieszczanie obrazu i tekstu wewnątrz pomocnika link_to (Rails)?

<% like = image_tag("like.png", :alt => "like", :class => "like") %> 
<%= link_to like, vote_up_path(@votable, :votable_type => "Post"), :remote => true, :class => "vote-up default button" %> 

Jak mogę to zrobić tak, że mogę umieścić jakiś tekst w linku i zaraz po obrazie (jak jak przycisk w YouTube)?

Odpowiedz

14

można przekazać blok do link_to pomocnika

<%= link_to vote_up_path(@votable, :votable_type => "Post"), :remote => true, :class => "vote-up default button" do %> 
    <%= image_tag("like.png", :alt => "like", :class => "like") %> 
    <span>Like</span> 
<% end %> 
1
<% like = image_tag("like.png", :alt => "like", :class => "like") %> 
<%= link_to "#{like} your text", vote_up_path(@votable, :votable_type => "Post"), :remote => true, :class => "vote-up default button" %> 
+0

' # {like} 'wypisuje tag img jako ciąg. – alexchenco

+0

ok, twoje prawo. <% = link_do image_tag ("like.png",: alt => "like",: class => "like") + "twój tekst", vote_up_path (@votable,: votable_type => "Post"), : remote => true,: class => "domyślny przycisk głosowania"%> będzie działać. Ale wariant blokowy to o wiele więcej najlepszych praktyk. – Daniel

2

na wszelki wypadek ktoś tu używa Slim jako silnik widoku w Rails 4 można zrobić:

= link_to root_path 
    = image_tag 'logo.png' 
Powiązane problemy