Sha256: df67a38c295e2e54988ceef42b2467ce215d29aac1ee55793e093d83f687e59d

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require_dependency "phcdevworks_scripts/application_controller"

module PhcdevworksScripts
  class Snippet::UrlsController < ApplicationController

    # Filters & Security
    #include PhcdevworksCore::PhcpluginsHelper
    #before_action :authenticate_user!
    before_action :set_paper_trail_whodunnit
    before_action :set_snippet_url, only: [:show, :edit, :update, :destroy]

    # INDEX
    def index
      @script_urls = snippet_post.urls.all
    end

    # SHOW
    def show
      @script_url = snippet_post.urls.find(params[:id])
    end

    # NEW
    def new
      @script_url = snippet_post.urls.build
    end

    # EDIT
    def edit
    end

    # CREATE
    def create
      @script_url = snippet_post.urls.create(script_url_params)
      @script_url.user_id = current_user.id
      if @script_url.save
        redirect_to script_snippet_urls_path, :flash => { :success => 'Script url was successfully created.' }
      else
        render :new
      end
    end

    # UPDATE
    def update
      @script_snippet = Snippet::Url.find(params[:snippet_id])
      if @script_url.update(script_url_params)
        redirect_to script_snippet_urls_path, :flash => { :success => 'Script url was successfully updated.' }
      else
        render :edit
      end
    end

    # DELETE
    def destroy
      @script_url = snippet_post.urls.find(params[:id])
      @script_url.destroy
      redirect_to script_snippet_urls_path, :flash => { :error => 'Script url was successfully destroyed.' }
    end

    private

    # Common Callbacks
    def set_snippet_url
      @snippet_url = Snippet::Url.friendly.find(params[:id])
    end

    def snippet_post
      @snippet_post = Snippet::Post.friendly.find(params[:post_id])
    end

    # Whitelist
    def snippet_url_params
      params.require(:snippet_url).permit(:snippet_url)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
phcdevworks_scripts-1.0.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-0.1.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb