简体   繁体   English

js文件中的多行HTML代码:Ruby on Rails

[英]MultiLine Html Code in js file :Ruby on Rails

I want to add text/body/ruby code in .html function but whenever I try to align my text properly by using enter key it is not functioning properly.我想在 .html 函数中添加文本/正文/ruby 代码,但是每当我尝试使用回车键正确对齐文本时,它就无法正常运行。

$('div.showcomment').html('<% @comments.each do |comment| %><%= comment.body %><%= link_to 'Delete Comment', articles_deletecomment_path(:id =>comment.id ,:articleid=>@article.id), method: :delete, :remote => true,data: { confirm: 'Are you sure?' } %><a onClick="editComment(<%= comment.id%>)">Edit Comment</a></br><% end %>');

How can i change this code so that it can expanded over multiple lines for better readibility我如何更改此代码以便它可以扩展到多行以获得更好的可读性

use a partial and pass @comments as a collection使用部分并将@comments作为集合传递

$('div.showcomment').html('<%= escape_javascript render(partial: 'comments/comment', collection: @comments, locals: { article: @article } %>')

# app/views/comments/_comment.html.erb
<%= comment.body %>
<%= link_to 'Delete Comment', articles_deletecomment_path(id: comment.id, article_id: article.id), method: :delete, remote: true, data: { confirm: 'Are you sure?' } %>
<a onclick="editComment(<%= comment.id%>)">Edit Comment</a>
<br>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM