I am using link_to img tag like following
<%= link_to image_tag("Search.png", :border=>0, :class => 'dock-item'), :action => 'search', :controller => 'pages'%><span>Search</span></a>
Which results in following html
<a href="/pages/search"><img alt="Search" border="0" class="dock-item" src="/images/Search.png?1264132800" /></a><span>Search</span></a>
I want the class="dock-item" to go to the <a>
tag instead of the img tag.
How can i change this?
Update:
<%= link_to image_tag("Search.png", :border=>0), :action => 'search', :controller => 'pages', :class => 'dock-item' %>
results in
<a href="/pages/search?class=dock-item"><img alt="Search" border="0" src="/images/Search.png?1264132800" /></a>
hi you can try doing this
link_to image_tag("Search.png", border: 0), {action: 'search', controller: 'pages'}, {class: 'dock-item'}
or even
link_to image_tag("Search.png", border: 0), {action: 'search', controller: 'pages'}, class: 'dock-item'
note that the position of the curly braces is very important, because if you miss them out, rails will assume they form a single hash parameters (read more about this here)
and according to the api for link_to:
link_to(name, options = {}, html_options = nil)
hope it helps! =)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With