我有用戶模型和評論模型使用acts_as_commentable_with_threading
我試圖把評論功能放在每個用戶的顯示頁面部分。
但是當我嘗試提交表單時,它顯示路由錯誤。
這是爲什麼?爲什麼我的表單不能正確提交?
錯誤
Routing Error
No route matches [POST] "/user/john/add_comment"
型號/ user.rb
acts_as_commentable
的意見/用戶/ show.html.erb
<%= render 'comment', :user => @user %>
的意見/用戶/ _comment.html.erb
<table>
<tr>
<th>ID</th>
<th>Title</th>
<th>Body</th>
<th>Subject</th>
<th>Posted by</th>
<th>Delete</th>
</tr>
<% @user.comment_threads.each do |comment| %>
<tr>
<td><%= comment.id %></td>
<td><%= comment.title %></td>
<td><%= comment.body %></td>
<td><%= comment.subject %></td>
<td><%= comment.user.user_profile.nickname if comment.user.user_profile %></td>
<td><%= button_to 'destroy', comment, confirm: 'Are you sure?', :disable_with => 'deleting...', method: :delete %></td>
</tr>
<% end %>
</table>
<%= form_for @user, :html => { :class => 'form-horizontal' } do |f| %>
<div class="field">
<%= f.label :body %><br />
<%= f.text_field :body %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
的routes.rb
get "user/:id/add_comment" => 'users#add_comment', :as => :add_comment_user
get "user/:id/delete_comment" => 'users#delete_comment', :as => :delete_comment_user
users_controller.rb
def add_comment
@user = User.find_by_username(params[:id])
@user_who_commented = current_user
@comment = Comment.build_from(@user, @user_who_commented.id, params[:users][:body])
@comment.save
redirect_to :controller => 'users', :action => 'show', :id => params[:users][:id]
flash[:notice] = "comment added!"
end
經過我有確切的錯誤。 –
@DaveNewton我剛剛加入 – HUSTEN