[英]MultiLine Html Code in js file :Ruby on Rails
我想在 .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 %>');
我如何更改此代碼以便它可以擴展到多行以獲得更好的可讀性
使用部分並將@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.