0
我正在開發一個簡單的論壇應用程序使用rails 4.0。我希望我的評論能夠發佈爲Ajax,而不是重新加載整個頁面,請幫助我。 這是我爲論壇Ajax發佈使用rails 4.0評論ForumThread
<div id="topic_content">
<h1>
<%= @topic.title %>
</h1>
<p>
<%= @topic.content %>
</p>
<div id="comments">
<h2>
<%= @topic.comments.count %>
Comments
</h2>
<%= render @topic.comments %>
<%if user_signed_in? && current_user.user? %>
<h3>Reply to thread</h3>
<%= render "comments/form" %>
<% end %>
</div>
<br/>
<hr/>
<br/>
<%if user_signed_in?%>
<% if can? :update, @topic %>
<%= link_to "Edit", edit_topic_path(@topic), class: "button" %>
<% end %>
<% if can? :delete, @topic %>
<%= link_to "Delete", topic_path(@topic), method: :delete, data: { confirm: "Are you sure you want to do this?" }, class: "button" %>
<% end %>
<% end %>
</div>
show.html.erb這是我_comment.html.erb部分
<div class="comment clearfix">
<div class="content">
<p class="comment_content">
<%= comment.comment %>
</p>
</div>
<div class="buttons">
<%if user_signed_in?%>
<% if can? :update, @topic => Comment %>
<%= link_to "Edit", edit_topic_comment_path(comment.topic, comment) %>
<% end %>
<% if can? :delete, @topic => Comment %>
<%= link_to "Delete", [comment.topic, comment], method: :delete, data: { confirm: "Are you sure?" } %>
<% end %>
<% end %>
</div>
你的代碼的其餘部分在哪裏? – bodyfarmer
你需要哪些文件請告訴我,以便我可以發佈它?我認爲這兩個文件就足夠了.......... – kali
ajax評論通常是在js控制器中完成的。 – bodyfarmer