Sha256: d2bded9999ea95acf7c3dded9745d84aa9416db708f415ae115ffc3ef98dd288

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require_dependency "blogr/application_controller"

module Blogr
  class CommentsController < ApplicationController

  	before_action :set_comment, only: [:show, :edit, :update, :destroy]

  	def index
  		@title = "Comments"
  		@comments = Blogr::Comment.all
  	end

  	def show
			@title = "Comment ##{@comment.id}"
		end

		def new
			@comment = Comment.new
			@title = "New Comment"
		end

		def edit
			@title = "Editing Comment by '#{@comment.author_name}'"
		end

		def create
			@comment = Comment.new(tag_params)

			if @comment.save
				redirect_to @comment, notice: 'Comment was successfully created.'
			else
				render action: 'new'
			end
		end

		def update
			if @comment.update(tag_params)
				redirect_to @comment, notice: 'Comment was successfully updated.'
			else
				render action: 'edit'
			end
		end

		def destroy
			@comment.destroy
			redirect_to comments_path, notice: 'Comment was successfully destroyed.'
		end

		private
			# Use callbacks to share common setup or constraints between actions.
			def set_comment
				@comment = Comment.find(params[:id])
			end

			def comment_params
				params.require(:comment).permit(:content, :author_name, :author_email)
			end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blogr-0.0.8 app/controllers/blogr/comments_controller.rb
blogr-0.0.7 app/controllers/blogr/comments_controller.rb
blogr-0.0.6 app/controllers/blogr/comments_controller.rb