Sha256: 8f53b1bbcb4a460c20c29f68ce04f2b28cdade7187d1d488381fa8182aa97e45
Contents?: true
Size: 1.07 KB
Versions: 21
Compression:
Stored size: 1.07 KB
Contents
class CommentsController < ApplicationController def index @comments = Comment.all end def show @comment = Comment.find(params[:id]) end def new @comment = Comment.new end def edit @comment = Comment.find(params[:id]) end def vote @comment = Comment.find(params[:id]) @comment.votes += params[:value].to_i @comment.save redirect_to(comments_url, :notice => 'Vote added!') end def create @comment = Comment.new(comment_params) if @comment.save redirect_to(@comment, :notice => 'Comment was successfully created.') else render "new" end end def update @comment = Comment.find(params[:id]) if @comment.update_attributes(comment_params) redirect_to(@comment, :notice => 'Comment was successfully updated.') else render "edit" end end # DELETE /comments/1 # DELETE /comments/1.xml def destroy @comment = Comment.find(params[:id]) @comment.destroy redirect_to(comments_url) end private def comment_params params.require(:comment).permit! end end
Version data entries
21 entries across 21 versions & 1 rubygems