添加自定义数据属性 rails 图像标记 [英] Adding custom data attributes rails image tag
本文介绍了添加自定义数据属性 rails 图像标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在我的 rails 应用程序中为 Galleria 添加数据描述和数据标题,但我看不到如何使用图像标签来做到这一点.到目前为止,我有这个:
<% @entries.each 做 |entry|%><%= image_tag entry.filename, :title =>"标题", :class =>"class", :data-description =>entry.caption, :data-title =>entry.caption %><%结束%>
但这会引发未定义的局部变量或方法描述"错误,那么我将如何在 rails 3 中执行此操作?
解决方案
正确的语法是
<%= image_tag entry.filename, :title =>"标题", :class =>"类", :data =>{:描述=>entry.caption, :title =>entry.caption } %>
I need to add data-description and data-title for galleria in my rails application but I can't see how to do this with the image tag. So far I have this:
<div id="galleria">
<% @entries.each do |entry| %>
<%= image_tag entry.filename, :title => "title", :class => "class", :data-description => entry.caption, :data-title => entry.caption %>
<% end %>
</div>
But this raises the undefined local variable or method `description' error, so how would I do this in rails 3?
解决方案
The correct syntax for this is
<%= image_tag entry.filename, :title => "title", :class => "class", :data => { :description => entry.caption, :title => entry.caption } %>
这篇关于添加自定义数据属性 rails 图像标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文