Sha256: 0f561592de1974508e6f3ed4530d94ebdd4d81c6e20deb52ec6a0352e6e2704a

Contents?: true

Size: 1.58 KB

Versions: 8

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true
require_dependency 'c/admin_controller'

module C
  class Admin::LocationsController < AdminController
    before_action :load_from_url, only: [:edit, :update, :destroy]
    load_and_authorize_resource class: C::Location

    def index
      @locations = filter_and_paginate(@locations, 'created_at desc')
    end

    def create
      @location = C::Location.new(location_params)
      if @location.save
        redirect_to locations_path, notice: 'Location created'
      else
        render :new
      end
    end

    def update
      if params[:commit] == 'upload'
        @location.assign_attributes(new_image_params)
        render :edit
      elsif @location.update(location_params)
        redirect_to locations_path, notice: 'Location updated'
      else
        render :edit
      end
    end

    def destroy
      @location.destroy
      respond_to do |format|
        format.js
        format.html { redirect_to locations_path }
      end
    end

    def sort
      @locations = C::Location.all
      @locations.update_order(params[:location])
      respond_to do |format|
        format.js { head :ok, content_type: 'text/html' }
      end
    end

    private

    def load_from_url
      @location = C::Location.get_from_url(params[:id])
    end

    def new_image_params
      params.require(:location).permit(new_images: [], images_attributes: [:id, :_destroy, :alt, :caption])
    end

    def location_params
      params.require(:location).permit(:name, :body, :published, C::Page::IMAGEABLE_ATTRIBUTES, C::Page::PAGE_INFO_ATTRIBUTES, new_images: [])
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cd2_catton_cms-1.1.35 app/controllers/c/admin/locations_controller.rb
cd2_catton_cms-1.1.34 app/controllers/c/admin/locations_controller.rb
cd2_catton_cms-1.1.33 app/controllers/c/admin/locations_controller.rb
cd2_catton_cms-1.1.32 app/controllers/c/admin/locations_controller.rb
cd2_catton_cms-1.1.31 app/controllers/c/admin/locations_controller.rb
cd2_catton_cms-1.1.30 app/controllers/c/admin/locations_controller.rb
cd2_catton_cms-1.1.20 app/controllers/c/admin/locations_controller.rb
cd2_catton_cms-1.1.10 app/controllers/c/admin/locations_controller.rb