I have a simple system in which photos have many comments.
I’m sure I’m not doing this right, but I am trying to build a simple rating system for the comments. comment.rating starts at 0 and can go up.
This is a portion of my Comments controller
class CommentsController < ApplicationController
def increment
@comment = Comment.find(params[:id])
@comment.rating += 1
redirect_to(@photo)
end
end
I think the increment method is fine, but how I’m calling it is not:
<%= link_to "+", :controller => 'comments', :method => 'increment' %>
That doesn’t work. I realize this is a bit of a fundamental question, but I’d appreciate any advice. Thanks.
I believe you are not passing a comment :id to params.
You could do so by defining a route like this in your
routes.rbfile:with your
incrementaction now beginning withand then call it from the view with
where
comment.idgives the id of the comment whose rating you want to increment