简体   繁体   English

Rails 3正确的image_tag转换

[英]Rails 3 correct image_tag conversion

I'm trying to convert parallax effect code to run on a Rails 3 app. 我正在尝试转换视差效果代码以在Rails 3应用程序上运行。 I can't get it to run so I'm wondering if I've converted this code properly. 我无法使其运行,所以我想知道我是否正确转换了此代码。 The first line in each group is the original code. 每组中的第一行是原始代码。 The second line in each group is my conversion. 每组的第二行是我的转换。 Can anyone tell me if this is right? 谁能告诉我这是否正确?

<article class="slide" id="showcasing" style="background:   url('backgrounds/landscape.png') repeat-x top center;">
<%= image_tag("backgrounds/landscape.png", :class => "slide", :id => "showcasing", :style => "background: repeat-x top center") %>

<img class="asset left-30 sp600 t120 z1" src="slides/scene1/macbook.png" />
<%= image_tag("slides/scene1/macbook.png", :class => "asset: left-30 sp600 t120 z1") %>

<article class="slide" id="ideas" style="background: url('backgrounds/aqua.jpg') repeat-x top center;">
<%= image_tag("backgrounds/aqua.jpg", :class => "slide", :id => "ideas", :style => "background: url('backgrounds/aqua.jpg') repeat-x top center") %>

<img class="asset left-480 sp600 t260 z1" src="img/slides/scene2/left.png" />
<%= image_tag("slides/scene2/left.png", :class => "asset left-480 sp600 t260 z1") %>

<img class="asset left-210 sp600 t213 z2" src="img/slides/scene2/middle.png" />
<%= image_tag("slides/scene2/middle.png", :class => "asset left-210 sp600 t213 z2") %>

<img class="asset left60 sp600 t260 z1" src="img/slides/scene2/right.png" />
<%= image_tag("slides/scene2/right.png", :class => "asset left60 sp600 t260 z1") %>

Everyone with an <article> tag was not right, because image_tag only yield <img /> tag. 每个带有<article>标签的人都不对,因为image_tag只产生<img />标签。 You should use image_path to yield a url and place it in style="background: url()" ( image_path API ). 您应该使用image_path生成一个URL并将其放置在style="background: url()"image_path API )中。

Other code should be like: 其他代码应类似于:

<%= image_tag("slides/scene1/macbook.png", :class => "asset left-30 sp600 t120 z1") %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM