Sha256: 2c5dcc59312979f79f341778c2c5a9123b5556c7d392615a8e497d36b85d3921

Contents?: true

Size: 1.41 KB

Versions: 7

Compression:

Stored size: 1.41 KB

Contents

class Admin::MenusController < Admin::ApplicationController
  belongs_to_app :menus
  add_breadcrumb 'Menus', :admin_menus_path
  before_action :load_menu, only: [:edit, :update, :show, :destroy]

  def index
    @menus = SpudMenu.all.paginate(page: params[:page])
    respond_with @menus
  end

  def new
    add_breadcrumb 'New', :new_admin_menu_path
    @menu = SpudMenu.new
    respond_with @menu
  end

  def create
    add_breadcrumb 'New', :new_admin_menu_path
    @menu = SpudMenu.new(menu_params)
    flash[:notice] = 'New menu created' if @menu.save
    respond_with @menu, location: !@menu.id.nil? ? admin_menu_menu_items_url(menu_id: @menu.id) : admin_menus_url
  end

  def edit
    add_breadcrumb "Edit #{@menu.name}", :edit_admin_menu_path
    respond_with @menu
  end

  def update
    add_breadcrumb "Edit #{@menu.name}", :edit_admin_menu_path

    flash[:notice] = 'Menu saved successfully' if @menu.update_attributes(menu_params)
    respond_with @menu, location: admin_menu_menu_items_url(menu_id: @menu.id)
  end

  def destroy
    flash[:notice] = 'Menu removed!' if @menu.destroy
    respond_with @menu, location: admin_menus_url
  end

  private

  def load_menu
    @menu = SpudMenu.where(id: params[:id]).first
    if @menu.blank?
      flash[:error] = 'Menu not found!'
      redirect_to(admin_menus_url()) && (return false)
    end
  end

  def menu_params
    params.require(:spud_menu).permit(:name)
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tb_cms-1.3.6 app/controllers/admin/menus_controller.rb
tb_cms-1.3.5 app/controllers/admin/menus_controller.rb
tb_cms-1.3.3 app/controllers/admin/menus_controller.rb
tb_cms-1.3.2 app/controllers/admin/menus_controller.rb
tb_cms-1.3.1 app/controllers/admin/menus_controller.rb
tb_cms-1.3.0 app/controllers/admin/menus_controller.rb
tb_cms-1.3.beta1 app/controllers/admin/menus_controller.rb