I am learning Rails, and am writing a simple app that will handle notes. Notes have a value “score” that is an integer. I want the user to press a button named “vote up” and one “vote down”, and voting up will make score=score+1.
The notes_controller.rb has a method ‘upvote’ that looks like
def upvote
@note = Note.find params[:id]
@note.score = @note.score +1
end
But I can not figure out how to route so that sending a POST (or UPDATE?) to /notes/:id/upvote makes the note’s score change?
in your routes file:
This will create the named route
upvote_note_pathwhich will point/notes/:id/upvote, and will run your NotesController upvote action.