Sha256: ed19b073b47754cec605a2ebe214d1f90fa05124103fd147de472b24613a779a

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

module Admin
  class MenusController < ApplicationController
    respond_to?(:before_action) ? before_action(:authenticate_user!) : before_filter(:authenticate_user!) # Devise

    helper EffectiveMenusAdminHelper

    layout (EffectivePages.layout.kind_of?(Hash) ? EffectivePages.layout[:admin] : EffectivePages.layout)

    def index
      @datatable = Effective::Datatables::Menus.new() if defined?(EffectiveDatatables)
      @page_title = 'Menus'

      authorize_effective_menus!
    end

    def new
      @menu = Effective::Menu.new()
      @page_title = 'New Menu'

      authorize_effective_menus!
    end

    def create
      @menu = Effective::Menu.new(menu_params)
      @page_title = 'New Menu'

      authorize_effective_menus!

      if @menu.save
        flash[:success] = 'Successfully created menu'
        redirect_to effective_pages.admin_menu_path(@menu)
      else
        flash.now[:danger] = 'Unable to create menu'
        render :action => :new
      end
    end

    def show
      @menu = Effective::Menu.find(params[:id])
      @page_title = @menu.to_s

      authorize_effective_menus!
    end

    private

    def authorize_effective_menus!
      EffectivePages.authorized?(self, :admin, :effective_pages)
      EffectivePages.authorized?(self, action_name.to_sym, @menu || Effective::Menu)
    end

    def menu_params
      params.require(:effective_menu).permit(:title)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
effective_pages-1.1.3 app/controllers/admin/menus_controller.rb
effective_pages-1.1.2 app/controllers/admin/menus_controller.rb
effective_pages-1.1.1 app/controllers/admin/menus_controller.rb