【问题标题】:syntax error, unexpected kENSURE js.erb rails语法错误,意外的 kENSURE js.erb rails
【发布时间】:2015-05-18 13:34:46
【问题描述】:

我的 rails 项目中的视图 create.js.erb 有一点问题。如果有 id 为 JTBDS 的应答器,我想执行 2 个不同的代码块。

这是我的代码:

if( $("#JTBDS").length ){
  $("#T<%= @current_tweet %>").after("<%= escape_javascript(render(:partial => @jtbd) %>"));
  $("#E<%= @current_tweet %>").hide();

  $(".jtbd_tags").each(function(){
    select($(this)[0].name,
    "http://localhost:3000/search",
    "tag_jtbd");
  });

  tag_button();

  $(".tags").each(function(){
      select($(this)[0].name,
             "http://localhost:3000/adrs",
             "tag");
  });
}

else{
  $("#T<%= @current_tweet %>").before("<%= escape_javascript(render(:partial => @jtbd, :layout => "jtbd_of_tweet",  locals: {jtbd: @jtbd} )) %>");
  $("#E<%= @current_tweet %>").hide();

  $(".jtbd_tags").each(function(){
    select($(this)[0].name,
    "http://localhost:3000/search",
    "tag_jtbd");
  });
}

我不知道为什么,但我有一个错误:语法错误,意外的 kENSURE

我尝试使用 console.log 打印 $("#JTBDS").length 并且我有预期的 0 或 1。

感谢您的帮助

【问题讨论】:

    标签: javascript ruby-on-rails ruby erb


    【解决方案1】:

    您在第 2 行缺少 escape_javascript 的右括号。

     $("#T<%= @current_tweet %>").after("<%= escape_javascript(render(:partial => @jtbd)) %>"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-11
      • 2015-08-19
      • 1970-01-01
      • 1970-01-01
      • 2016-05-02
      • 2012-04-20
      • 2015-04-02
      相关资源
      最近更新 更多