我只想在图像上做一个简单的链接.
<a href="http://www.mysite.com"><img src="path/to/image.png"/></a>
Run Code Online (Sandbox Code Playgroud)
你如何使用link_to rails标签做到这一点?
Mic*_*ley 68
使用一个image_tag
用于的内容link_to
.
link_to image_tag("path/to/image.png"), "http://www.mysite.com/"
Run Code Online (Sandbox Code Playgroud)
Jac*_*iel 24
我的解决方案
<%= link_to root_path do %>
<%= image_tag "image.jpg", class: "some css class here" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
Pra*_*vin 11
干一个
在你的application_helper.rb
def link_to_image(image_path, target_link,options={})
link_to(image_tag(image_path, :border => "0"), target_link, options)
end
Run Code Online (Sandbox Code Playgroud)
然后从你的意见
<%= link_to_image("path/to/image", some_url) %>
Run Code Online (Sandbox Code Playgroud)
<%= link_to(image_tag("path/to/image.png"), root_path) %>
Run Code Online (Sandbox Code Playgroud)
root_path
您网站主页的路线在哪里.
归档时间: |
|
查看次数: |
40771 次 |
最近记录: |