Sha256: 5517c52d0dfdcc8392d017807a4ef4690942b608a6eced3bb0a07c937e7d7b47

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

module Adminpanel
  class GalleriesController < Adminpanel::ApplicationController
    load_and_authorize_resource

    def index
      @galleries = Gallery.all
    end

    # def show
    #   @gallery = Gallery.find(params[:id])
    # end

    # def edit
    #   @gallery = Gallery.find(params[:id])
    # end

    def create
      @gallery = Gallery.new(params[:gallery])

      if @gallery.save
        redirect_to gallery_path(@gallery), :notice => t("gallery.success")
      else
        render 'new'
      end
    end

    def move_better
      @gallery = Gallery.find(params[:id])
      if @gallery.move_to_better_position
        flash[:success] = t("gallery.moved")
      else
        flash[:warning] = t("gallery.not-moved")
      end
      respond_to do |format|
        format.html do
          redirect_to galleries_path
        end
        format.js do
          @galleries = Gallery.all
          render :locals => { :galleries => @galleries }
        end
      end
    end

    def move_worst
      @gallery = Gallery.find(params[:id])
      if @gallery.move_to_worst_position
        flash[:success] = t("gallery.moved")
      else
        flash[:warning] = t("gallery.not-moved")
      end
      respond_to do |format|
        format.html do
          redirect_to galleries_path
        end
        format.js do
          @galleries = Gallery.all
          render :locals => { :galleries => @galleries }
        end
      end
    end

    def destroy
      @gallery = Gallery.find(params[:id])
      @gallery.destroy

      redirect_to galleries_path, :notice => t("gallery.deleted")
    end

    def update
      @gallery = Gallery.find(params[:id])
      if @gallery.update_attributes(params[:gallery])
        redirect_to gallery_path(@gallery)
      else
        render 'edit'
      end
    end

    # def new
    #   @gallery = Gallery.new
    # end

    private
    def gallery_params
      params.require(:gallery).permit(:file)

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adminpanel-2.0.1 app/controllers/adminpanel/galleries_controller.rb
adminpanel-2.0.0 app/controllers/adminpanel/galleries_controller.rb