Sha256: 52f7a1fd64a213159ae57d41b017c95e161dca5fe9d0507ed597d4a5e79f3476

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

# Load General Controller for Engine
require_dependency "phcpress/application_controller"

# Code for Blog Posting
module Phcpress
	class Blog::PostsController < ApplicationController

		# Filters & Security
		before_action :set_blog_post, only: [:edit, :update, :destroy]

		# Blog Post Index (/blog/posts)
		def index
			@blog_posts = Blog::Post.all
		end

		# Single Blog Post (/blog/posts/1)
		#def show
		#end

		# Create a New Blog Post (/blog/posts/new)
		def new
			@blog_post = Blog::Post.new
		end

		# Edit Blog Post (/blog/posts/1/edit)
		def edit
		end

		# POST
		def create
			@blog_post = Blog::Post.new(blog_post_params)

			if @blog_post.save
				redirect_to blog_posts_path, notice: 'Blog post was successfully created.'
			else
				render :new
			end
		end

		# PATCH/PUT
		def update
			if @blog_post.update(blog_post_params)
				redirect_to blog_posts_path, notice: 'Blog post was successfully updated.'
			else
				render :edit
			end
		end

		# DELETE
		def destroy
			@blog_post.destroy
			redirect_to blog_posts_path, notice: 'Blog post was successfully destroyed.'
		end

		private

		# Common Callbacks
		def set_blog_post
		@blog_post = Blog::Post.find(params[:id])
		end

		# Whitelist on what can be posted
		def blog_post_params
			params.require(:blog_post).permit(:blogpsttitle, :blogpsttext, :pststatus)
		end

	end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
phcpress-0.7.9 app/controllers/phcpress/blog/posts_controller.rb
phcpress-0.6.0 app/controllers/phcpress/blog/posts_controller.rb
phcpress-0.5.9b app/controllers/phcpress/blog/posts_controller.rb
phcpress-0.4.9b app/controllers/phcpress/blog/posts_controller.rb
phcpress-0.4.5b app/controllers/phcpress/blog/posts_controller.rb
phcpress-0.4.1b app/controllers/phcpress/blog/posts_controller.rb