Sha256: 0796ce28c4aba5af2d88cc00353eaae2d27c421ef1f4c40dea62bde6ce2eefca

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require_dependency "phccodesnipper/application_controller"

module Phccodesnipper
	class Script::SnippetsController < ApplicationController

		# Include Core Helpers, Security & Action Filters
		include PhcdevworksCore::PhcdevPluginsHelper
		before_action :authenticate_user!
		before_action :set_script_snippet, only: [:show, :edit, :update, :destroy]

		# INDEX
		def index
			@script_snippets = Script::Snippet.all
		end

		# SHOW
		def show
		end

		# NEW
		def new
			@script_snippet = Script::Snippet.new
		end

		# EDIT
		def edit
		end

		# CREATE
		def create
			@script_snippet = Script::Snippet.new(script_snippet_params)
			if @script_snippet.save
				redirect_to @script_snippet, :flash => { :success => 'Code snippet was successfully created.' }
			else
				render :new
			end
		end

		# UPDATE
		def update
			if @script_snippet.update(script_snippet_params)
				redirect_to @script_snippet, :flash => { :success => 'Code snippet was successfully updated.' }
			else
				render :edit
			end
		end

		# DELETE
		def destroy
			@script_snippet.destroy
			redirect_to script_snippets_url, :flash => { :error => 'Code snippet was successfully destroyed.' }
		end

		private

		# Common Callbacks
		def set_script_snippet
			@script_snippet = Script::Snippet.find(params[:id])
		end

		# Whitelist
		def script_snippet_params
			params.require(:script_snippet).permit(:snippet_title, :snippet_code)
		end

	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phccodesnipper-6.1.0 app/controllers/phccodesnipper/script/snippets_controller.rb