【问题标题】:SyntaxError in Campaign_groups#showCampaign_groups 中的语法错误#show
【发布时间】:2012-01-21 12:46:31
【问题描述】:

我看了很多,只是找不到语法错误,我不断收到:

compile error
/home/durrantm/code/it_trunk/webapp/app/views/campaign_groups/_cgs_overview.html.erb:36: syntax error, unexpected kELSE, expecting ')'
;  else ; @output_buffer.concat "\n  ...
       ^
/home/durrantm/code/it_trunk/webapp/app/views/campaign_groups/_cgs_overview.html.erb:40: syntax error, unexpected kEND, expecting ')'
;  end ; @output_buffer.concat "\n\n"
      ^
/home/durrantm/code/it_trunk/webapp/app/views/campaign_groups/_cgs_overview.html.erb:43: syntax error, unexpected kENSURE, expecting ')'
/home/durrantm/code/it_trunk/webapp/app/views/campaign_groups/_cgs_overview.html.erb:45: syntax error, unexpected kEND, expecting ')'

页面(_cgs_overview.html.erb)的整个代码是:

<% if @campaign_group.campaigns.count > 0 %>
    <%=# render :partial => 'show_offer_images' %>
    <div class="overview">

      <table class="show_activity show_overview">
        <tr>
          <th>Unique Shoppers</th>
          <td id="overview-shoppers" class="clearable">-</td>
        </tr>
        <tr>
          <th>Issuances</th>
          <td id="overview-issuances" class="clearable">-</td>
        </tr>
        <tr>
          <th>Redemptions</th>
          <td title="Redemption rate does not include informational campaigns" id="overview-redemptions" class="clearable">-</td>
        </tr>
        <tr>
          <th>Total Cost</th>
          <td id="overview-cost" class="clearable">-</td>
        </tr>
        <tr>
          <th>Products</th>
          <td id="overview-products" class="clearable">-</td>
        </tr>
      </table>
    </div>
    <div style="clear:both;"></div>

    <div style="width:300px; padding-bottom: 10px">
      <%=# link_to("<<", campaign_group_path(params[:id], :offer_images_offset_for_pagination => @previous_images_to_paginate )) %>&nbsp;&nbsp;
      <%=# link_to(">>", campaign_group_path(params[:id], :offer_images_offset_for_pagination => @next_images_to_paginate )) %>&nbsp;&nbsp;
      <%=# link_to(">ajax>", :remote => true, :action => 'show_offer_images', :campaign_group_id => params[:id], :offer_images_offset_for_pagination => @next_images_to_paginate ) %>
    </div>

<% else %>
    <p style="font-size:120%;font-style:italic;margin:140px 0 160px;">
      There are no campaigns in this group.
    </p>
<% end %>

【问题讨论】:

  • 把它分成两半,本地化,就像 git bisect 做的那样
  • 您应该做的第一件事是删除所有注释行,例如&lt;%=# render :partial =&gt; .... %&gt;,然后重试
  • 谢谢大家,我在发帖前已经尝试过上述方法。还是卡住了。这个真的很奇怪,这就是我发布它的原因
  • 我删除了中间的 html 表格并将其替换为 ';table' 但没有运气

标签: ruby-on-rails ruby syntax show erb


【解决方案1】:

如果您让erb 向您显示ruby 代码,通过-x 开关,您将看到

... _erbout.concat((# render :partial ...)); _erbout.concat "\n"

请注意# 哈希如何将整行的其余部分输出。这条线和其他三个类似的线是“expecting ')'”的原因。

搜索 erb 评论 指向 Best way to add comments in erb,我们了解到您应该将 &lt;%=# ... %&gt; 替换为 &lt;%#= ... %&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多