Sha256: 43581df97045874e6059f9c2b85b1594a37862c38874229e9e1acb5fe0c17be0

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

require_dependency "phcpress/application_controller"

module Phcpress
	class News::PostsController < ApplicationController

		# Filters & Security
		layout 'layouts/phcpress/newspost/news_layout'
		before_action :authenticate_user!
		before_action :current_user
		before_action :set_news_post, only: [:edit, :update, :destroy]

		# News Post Index
		def index
			@news_posts = News::Post.all
		end

		# New News Article
		def new
			@news_post = News::Post.new
		end

		# Edit News Article
		def edit
		end

		# Create News Article
		def create
			@news_post = News::Post.new(news_post_params)
			@news_post.user_id = current_user
			if @news_post.save  
				redirect_to news_posts_path, notice: 'News Article was Successfully Created.'
				else
					render 'new'
			end
		end

		# Update News Article
		def update
			if @news_post.update(news_post_params)
				redirect_to news_posts_path, notice: 'News Article was Successfully Updated.'
			else
				render :edit
			end
		end

		# Delete News Destroy
		def destroy
			@news_post.destroy
			redirect_to news_posts_path, notice: 'News Article was Successfully Destroyed.'
		end

		private

		# Common Callbacks
		def set_news_post
			@news_post = News::Post.find(params[:id])
		end

		# Whitelist
		def news_post_params
			params.require(:news_post).permit(:newspsttitle, :newspsttext, :newspstexcerpts, :pststatus, :pstimage, :user_id, :category_id)
		end

		# Current User
		def current_user
			return unless session[:user_id]
			@current_user ||= User.find(session[:user_id])
		end

	end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
phcpress-3.8.1 app/controllers/phcpress/news/posts_controller.rb
phcpress-3.8.0 app/controllers/phcpress/news/posts_controller.rb
phcpress-3.7.9 app/controllers/phcpress/news/posts_controller.rb
phcpress-3.7.8 app/controllers/phcpress/news/posts_controller.rb
phcpress-3.7.7 app/controllers/phcpress/news/posts_controller.rb
phcpress-3.7.6 app/controllers/phcpress/news/posts_controller.rb
phcpress-3.7.5 app/controllers/phcpress/news/posts_controller.rb