Sha256: e3ef430c1269550ed8dfcf6d191d9a7a7648cc0b7a93f0c0fab10683e923726b

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

require_dependency "phccodesnipper/application_controller"

module Phccodesnipper
  class Script::SnippetsController < ApplicationController

    # Include Core Helpers, Security & Action Filters
    include Phccorehelpers::PhcpluginsHelper
    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 => '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 => 'Snippet was successfully updated.' }
      else
        render :edit
      end
    end

    # DELETE
    def destroy
      @script_snippet.destroy
      redirect_to script_snippets_url, :flash => { :error => '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

7 entries across 7 versions & 1 rubygems

Version Path
phccodesnipper-5.4.0 app/controllers/phccodesnipper/script/snippets_controller.rb
phccodesnipper-5.3.0 app/controllers/phccodesnipper/script/snippets_controller.rb
phccodesnipper-5.2.0 app/controllers/phccodesnipper/script/snippets_controller.rb
phccodesnipper-5.1.0 app/controllers/phccodesnipper/script/snippets_controller.rb
phccodesnipper-5.0.0 app/controllers/phccodesnipper/script/snippets_controller.rb
phccodesnipper-4.0.0 app/controllers/phccodesnipper/script/snippets_controller.rb
phccodesnipper-3.0.0 app/controllers/phccodesnipper/script/snippets_controller.rb