ruby-on-rails - 找不到: syntax error, unexpected '>' in ROR app的原因

标签 ruby-on-rails ruby syntax-error carousel

好的,这可能是愚蠢的,但是我整夜都在努力寻找代码中此错误的原因,但是没有运气。

我的最后一个选择是看看您的眼睛是否比我的眼睛更好。

我在下面的行(第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 ')'

最佳答案

您不能嵌套<% %>,而需要使用字符串插值,如下所示:

<%= 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" : "" %>

关于ruby-on-rails - 找不到: syntax error, unexpected '>' in ROR app的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45517173/

相关文章:

ruby - 如何禁止在 RSpec 中显示挂起(跳过)的规范?

ruby - 读取/分配实例变量的接受 block

javascript - 嵌套的 JSON 调用给出 : Uncaught SyntaxError: Missing } in template expression

ruby-on-rails - 使用 `update_all` 时运行验证

ruby-on-rails - 如果在SET操作期间redis超时,redis db中的数据是否已经被修改?

ruby-on-rails - ActiveAdmin单表继承公共(public)属性表单重写

ruby - 如何调用在不同上下文中获取 block 的 Proc?

python - python open语句中的反斜杠错误

c# - Visual Studio 在构建后显示虚假错误

javascript - 每次由 Rails 中的 Vanilla Javascript 加载部分时查询选择元素