好吧,这可能是愚蠢的,但我花了整整一夜试图在我的代码中找到导致此错误的原因而没有运气。
我的最后一个选择是看你的眼睛是否比我的眼睛更好。
我在下面的一行(第68行)中收到此错误:
<%= image_tag image_product.image.url(:medium), class: "img-responsive", id: "<%= index == 0 ? 'zoom_05' : '' %>" %>
完整的摘录如下:
<div class='carousel-inner '>
<% @product.images.each_with_index do |image_product, index| %>
<div class=<%= index == 0 ? 'item active' : '' %> >
<%= image_tag image_product.image.url(:medium), class: "img-responsive", id: "<%= index == 0 ? 'zoom_05' : '' %>" %>
</div>
<% end %>
<script>
$("#zoom_05").elevateZoom({ zoomType : "inner", cursor: "crosshair" });
</script>
</div>
<!-- sag sol -->
<a class='left carousel-control' href='#carousel-custom' data-slide='prev'>
<span class='glyphicon glyphicon-chevron-left'></span>
</a>
<a class='right carousel-control' href='#carousel-custom' data-slide='next'>
<span class='glyphicon glyphicon-chevron-right'></span>
</a>
</div>
完整的错误消息:
syntax error, unexpected '>'
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:74: unknown regexp options - crpt
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:75: syntax error, unexpected '<'
</div>
^
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:78: unknown regexp options - pa
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:79: syntax error, unexpected '<'
</a>
^
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:81: unknown regexp options - pa
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:82: syntax error, unexpected '<'
</a>
^
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:83: unknown regexp options - dv
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:84: syntax error, unexpected '<'
<!-- thumb -->
^
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:84: syntax error, unexpected unary-, expecting keyword_do or '{' or '('
<!-- thumb -->
^
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:86: syntax error, unexpected keyword_do_LAMBDA
...oduct.images.each_with_index do |image_product, index|
... ^
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:86: syntax error, unexpected '|', expecting '='
...index do |image_product, index|
... ^
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:90: syntax error, unexpected keyword_end, expecting ')'
'.freeze; end
^
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:135: syntax error, unexpected keyword_ensure, expecting ')'
/Users/dadi/Documents/Vefir/stores/hlinreykdal/app/views/products/show.html.erb:137: syntax error, unexpected keyword_end, expecting ')'
答案 0 :(得分:1)
你不能嵌套<% %>
,你需要使用字符串插值,如下所示:
<%= image_tag image_product.image.url(:medium), class: "img-responsive", id: "#{index == 0 ? 'zoom_05' : ''}" %>
虽然,因为你已经使用了ruby代码,所以你根本不需要任何插值,所以你可以这样做:
<%= image_tag image_product.image.url(:medium), class: "img-responsive", id: index == 0 ? "zoom_05" : "" %>
答案 1 :(得分:0)
快速猜测是:
<%= image_tag image_product.image.url(:medium), class: "img-responsive", id: "<%= index == 0 ? 'zoom_05' : '' %>" %>
应该是这样的:
<%= image_tag image_product.image.url(:medium), class: "img-responsive", id: "#{index == 0 ? 'zoom_05' : ''}" %>
具体来说,交换:
<%= index == 0 ? 'zoom_05' : '' %>
有:
#{index == 0 ? 'zoom_05' : ''}
您的问题很可能已经在<%= %>
行,因此您无法在<%= %>
内再次执行此操作。
答案 2 :(得分:0)
你误用<%=
不必要地执行字符串插值。
<%=
标记是ERB的一部分,您无法嵌套它们。在<% %>
内部,您不再处于ERB上下文中,您正在编写纯Ruby。如果您要执行字符串插值,则可以使用"#{ ... }"
。但是,这里根本不需要字符串插值。
您的行应为:
<%= image_tag image_product.image.url(:medium), class: "img-responsive", id: (index == 0 ? 'zoom_05' : '') %>