test/dummy/app/controllers/comments_controller.rb in merit-1.5.0 vs test/dummy/app/controllers/comments_controller.rb in merit-1.6.0

- old
+ new

@@ -1,40 +1,18 @@ class CommentsController < ApplicationController - # GET /comments - # GET /comments.xml def index @comments = Comment.all - - respond_to do |format| - format.html # index.html.erb - format.xml { render :xml => @comments } - end end - # GET /comments/1 - # GET /comments/1.xml def show @comment = Comment.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.xml { render :xml => @comment } - end end - # GET /comments/new - # GET /comments/new.xml def new @comment = Comment.new - - respond_to do |format| - format.html # new.html.erb - format.xml { render :xml => @comment } - end end - # GET /comments/1/edit def edit @comment = Comment.find(params[:id]) end def vote @@ -42,49 +20,37 @@ @comment.votes += params[:value].to_i @comment.save redirect_to(comments_url, :notice => 'Vote added!') end - # POST /comments - # POST /comments.xml def create - @comment = Comment.new(params[:comment]) - - respond_to do |format| - if @comment.save - format.html { redirect_to(@comment, :notice => 'Comment was successfully created.') } - format.xml { render :xml => @comment, :status => :created, :location => @comment } - else - format.html { render "new" } - format.xml { render :xml => @comment.errors, :status => :unprocessable_entity } - end + @comment = Comment.new(comment_params) + if @comment.save + redirect_to(@comment, :notice => 'Comment was successfully created.') + else + render "new" end end - # PUT /comments/1 - # PUT /comments/1.xml def update @comment = Comment.find(params[:id]) - - respond_to do |format| - if @comment.update_attributes(params[:comment]) - format.html { redirect_to(@comment, :notice => 'Comment was successfully updated.') } - format.xml { head :ok } - else - format.html { render "edit" } - format.xml { render :xml => @comment.errors, :status => :unprocessable_entity } - end + 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 - respond_to do |format| - format.html { redirect_to(comments_url) } - format.xml { head :ok } - end + private + + def comment_params + params.require(:comment).permit! end end