Sha256: 48bcaadc7ec714065b44f075a08ab6467dd920d567e41a0dad742f33611c7192

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

module Intro
  module Admin
    class ToursController < ::Intro::Admin::ApplicationController
      if Rails::VERSION::MAJOR > 3
        before_action :authenticate
        before_action :require_tour, except: [:index, :new, :create, :route, :attempt]
      else
        before_filter :authenticate
        before_filter :require_tour, except: [:index, :new, :create, :route, :attempt]
      end

      def index
        @tours = Intro::Tour.page(params[:page]).per(15)
        @tours = @tours.recent
      end

      def new
        @tour = Intro::Tour.new
      end

      def create
        @tour = Intro::Tour.new(tour_params)

        if @tour.save
          redirect_to admin_tour_path(@tour), notice: t('intro.admin.add_success')
        else
          render :new
        end
      end

      def route
        render json: { data: Intro::Tour.extract_route(params[:path]) }
      end

      def attempt
        tour = Intro::Tour.new(tour_params)
        render json: { data: tour.expose_attributes }
      end

      def show
        render :edit
      end

      def edit; end

      def update
        flash.now[:notice] = t('intro.admin.update_success') if @tour.update(tour_params)
        render :edit
      end

      def destroy
        @tour.destroy
        redirect_to admin_tours_path
      end

      def publish
        @tour.update(published: 'true' == params[:published])
        redirect_to :back
      rescue => e
        redirect_to admin_tours_path
      end

      protected

      def tour_params
        _params = params[:tour].slice(:ident, :controller_path, :action_name, :options, :route, :expired_at)
        _params.permit! if Rails::VERSION::MAJOR > 3
        _params
      rescue
        {}
      end

      def require_tour
        @tour = Intro::Tour.find_by_id(params[:tour_id].presence || params[:id])

        @tour || respond_to do |format|
          format.html { redirect_to admin_tours_path }
          format.any  { head :not_found  }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
intro-0.4.1 app/controllers/intro/admin/tours_controller.rb
intro-0.4.0 app/controllers/intro/admin/tours_controller.rb