我創建了評論系統來提供創建評論和回覆它們的功能。 我用http://www.sitepoint.com/nested-comments-rails/指南。工作完美。但在這個例子中,回覆一些評論時,它會轉到其他路徑,這就是我想要避免的。回覆在同一頁面中評論不在評論/新建路徑,Rails 4
目前代碼: Advertisement#show這裏我想創建回覆評論。
<%= comments_tree_for @comments %>
<h1>New comment</h1>
<%= render 'comments/form' %>
_comment.html.rb
<div class="well">
<h2><%= comment.title %></h2>
<p class="text-muted"><%= comment.root? ? "Started by" : "Replied by" %> <strong><%= comment.author %></strong> on
<%= l(comment.created_at, format: '%B, %d %Y %H:%M:%S') %></p>
<blockquote>
<p><%= comment.body %></p>
</blockquote>
<% from_reply_form ||= nil %>
<% unless from_reply_form %>
<% if comment.leaf? %>
<small class="text-muted">There are no replies yet - be the first one to reply!</small>
<% end %>
<p><%= link_to 'reply', new_comment_path(comment.id) %></p>
<% end %>
</div>
_form.html.erb
<%= form_for(@comment) do |f| %>
<% if @comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
<ul>
<% @comment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.hidden_field :advertisement_id, :value => @advertisement.id%>
<%= f.hidden_field :user_id, :value => current_user.id%>
<%= f.hidden_field :parent_id %>
<div class="form-group">
<%= f.label :body %>
<%= f.text_area :body, class: 'form-control', required: true %>
</div>
<%= f.submit class: 'btn btn-primary' %>
<% end %>
是否有值得信賴的指南,以幫助我嗎?
只是要求你打的創建方法時您發表的帖子或者你是不是? – 2014-12-03 21:09:55
@Aaditi Jain你的意思是當我創建評論?還是廣告? – Edgars 2014-12-04 10:33:45