Ruby 在rails中从javascript调用时链接到中断javascript?

Ruby 在rails中从javascript调用时链接到中断javascript?,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,我有一张表格,上面写着一个“想法”。我已经用ajax设置好了它。 它基本上只是将想法和发布想法的用户附加到想法列表的末尾。 在create.js.erb中使用此javascript可以正常工作 $('#thoughts') .append("<div class='thoughts'><%= @thought.user.name %><p><%= @thought %></p></div>"); $(“#想法”) .追

我有一张表格,上面写着一个“想法”。我已经用ajax设置好了它。 它基本上只是将想法和发布想法的用户附加到想法列表的末尾。 在create.js.erb中使用此javascript可以正常工作

$('#thoughts')
  .append("<div class='thoughts'><%= @thought.user.name %><p><%= @thought %></p></div>");
$(“#想法”)
.追加(“

”);
但是,当我试图添加一个链接到用户谁张贴了这样的想法

$('#thoughts')
  .append("<div class='thoughts'><%= link_to(@thought.user.name, @thought.user) %><p><%= @thought %></p></div>");
$(“#想法”)
.追加(“

”);
它会将想法附加到想法列表中。它仍然会将其发布到数据库,但不会显示它


非常感谢您的帮助。

您必须像这样使用
escape\u javascript

$('#thoughts')
  .append("<div class='thoughts'><%= escape_javascript(link_to(@thought.user.name, @thought.user)) %><p><%= @thought %></p></div>");
$('#thoughts')
  .append("<div class='thoughts'><a href="/thoughts/1">Username</a><p>Thought</p></div>");
                                       # ^
                                       # This is the problem,
                                       # which is fixed by escape_javascript