Ruby on rails 3 Rails 3-使用图像标签和x2B链接到;文本 'controller\u name',:action=>'action\u name'}), :class=>quick', :remote=>true)%%>
这部分代码将生成meimage.png作为链接。我需要将此图像附加一些文本(图像+文本),我尝试了以下方法:Ruby on rails 3 Rails 3-使用图像标签和x2B链接到;文本 'controller\u name',:action=>'action\u name'}), :class=>quick', :remote=>true)%%>,ruby-on-rails-3,image,link-to,Ruby On Rails 3,Image,Link To,这部分代码将生成meimage.png作为链接。我需要将此图像附加一些文本(图像+文本),我尝试了以下方法: <%= link_to ((image_tag 'image.png'), url_for({:controller => 'controller_name', :action => 'action_name'}), :class => 'quick', :remote => true)
<%= link_to ((image_tag 'image.png'),
url_for({:controller => 'controller_name', :action => 'action_name'}),
:class => 'quick',
:remote => true) %>
'controller\u name',:action=>'action\u name'}),
:class=>quick',
:remote=>true)%%>
和类似的方式,但每一次尝试都会以错误消息结束。。。有谁能帮我一下,我该怎么做
提前感谢。试试这个:
<%= link_to ((image_tag 'image.png', 'text'),
url_for({:controller => 'controller_name', :action => 'action_name'}),
:class => 'quick',
:remote => true) %>
'controller\u name',:action=>'action\u name'}),
:class=>quick',
:remote=>true)%%>
第一个参数是文本部分,您可以使用image_标记创建HTML,但您可以轻松地添加内容。试试这个
<%= link_to (image_tag('image.png') + text,
url_for({:controller => 'controller_name', :action => 'action_name'}),
:class => 'quick',
:remote => true) %>
'controller\u name',:action=>'action\u name'}),:class=>'quick',:remote=>true%>
我使用了以下方法,效果很好:
<%= link_to image_tag('/images/image.png') + "some extra text", url_for({:controller => 'controller_name', :action => 'action_name'}), :class => 'quick', :remote => true %>
稍微性感一点的解决方案
<%= link_to image_tag("logo.jpg"), controller: 'welcome' %>
“图像描述”,:class=>“css”),根路径%>
此外,图像标记位需要放在第一位,如果它位于“+”之后,它将被转义。您应该根据Rails 3语法更改答案。
<%= link_to image_tag("image.png", :alt => "Image Description", :class => "css"), root_path %>