Sha256: 2b38fff74b475d45e1466e9bd636993e7b3a25c5245e2e81b621b39e18b3acfd

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require_dependency "phcpresspro/application_controller"

module Phcpresspro
	class News::PostsController < ApplicationController

		# Filters & Security
		layout 'layouts/phcpresspro/newspost/news_layout'
		before_action :require_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.id
			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

		# Define Current User
		def current_user
			@_current_user ||= AuthRocket::Session.from_token(session[:ar_token]).try(:user)
		end

		# 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

	end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
phcpresspro-2.2.5 app/controllers/phcpresspro/news/posts_controller.rb
phcpresspro-2.2.3 app/controllers/phcpresspro/news/posts_controller.rb
phcpresspro-2.2.2 app/controllers/phcpresspro/news/posts_controller.rb
phcpresspro-2.2.1 app/controllers/phcpresspro/news/posts_controller.rb
phcpresspro-2.2.0 app/controllers/phcpresspro/news/posts_controller.rb
phcpresspro-2.1.3 app/controllers/phcpresspro/news/posts_controller.rb