2014-07-24 72 views
0

我想在.html函數中添加文本/正文/紅寶石代碼,但每當我嘗試使用回車鍵正確對齊我的文本時,它都無法正常運行。js文件中的MultiLine Html代碼:Ruby on Rails

$('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 %>'); 

我怎樣才能改變這種代碼,以便它可以擴展到多個行更好的可讀性

回答

2

使用的部分,並通過@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>