Sha256: 94412fe1fa0073b9e85fc5b77c814627ff7c4a065230992b9f16d146050353e1

Contents?: true

Size: 1.89 KB

Versions: 15

Compression:

Stored size: 1.89 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
      @snippet_urls = snippet_post.urls.all
    end

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

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

    # EDIT
    def edit
    end

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

    # UPDATE
    def update
      @snippet_post = Snippet::Post.friendly.find(params[:post_id])
      if @snippet_url.update(snippet_url_params)
        redirect_to snippet_post_urls_path, :flash => { :success => 'Script url was successfully updated.' }
      else
        render :edit
      end
    end

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

    private

    # Common Callbacks
    def set_snippet_url
      @snippet_url = Snippet::Url.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, :post_id, :slug, :user_id, :org_id)
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
phcdevworks_scripts-5.8.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-5.7.1 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-5.7.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-5.6.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-5.5.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-5.4.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-5.3.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-5.2.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-5.1.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-5.0.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-4.1.1 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-4.1.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-4.0.2 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-4.0.1 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb
phcdevworks_scripts-4.0.0 app/controllers/phcdevworks_scripts/snippet/urls_controller.rb