app/controllers/georgia/menus_controller.rb in georgia-0.7.8 vs app/controllers/georgia/menus_controller.rb in georgia-0.8.0

- old
+ new

@@ -1,20 +1,21 @@ module Georgia class MenusController < ApplicationController - load_and_authorize_resource class: Menu - def index - @menus = Menu.scoped.page(params[:page]) + @menus = Menu.all + authorize @menus end def new @menu = Menu.new + authorize @menu end def create - @menu = Menu.new(params[:menu]) + @menu = Menu.new(menu_params) + authorize @menu if @menu.save respond_to do |format| format.html { redirect_to [:edit, @menu], notice: "#{@menu.title} was successfully created." } format.js { render layout: false } end @@ -25,23 +26,27 @@ end end end def show - redirect_to edit_menu_path(params[:id]) + @menu = Menu.find(params[:id]) + authorize @menu + redirect_to [:edit, @menu] end def edit @menu = Menu.find(params[:id]) + authorize @menu @links = @menu.links.roots end def update @menu = Menu.find(params[:id]) + authorize @menu update_links_attributes(params[:menu].delete(:ancestry)) update_links_menu_id - if @menu.update_attributes(params[:menu]) + if @menu.update(menu_params) respond_to do |format| format.html { redirect_to [:edit, @menu], notice: "#{@menu.title} was successfully updated." } format.js { head :ok } end else @@ -52,10 +57,11 @@ end end def destroy @menu = Menu.find(params[:id]) + authorize @menu @menu.destroy redirect_to menus_url end @@ -72,9 +78,13 @@ Link.where(id: params[:menu][:links_attributes].keys).update_all(menu_id: params[:id]) end def ancestry_attributes(ancestry_tree) MenuAncestryParser.new(ancestry_tree).to_hash + end + + def menu_params + params.require(:menu).permit(:name, :ancestry, links_attributes: [:id, :_destroy, :position, :parent_id, contents_attributes: [:id, :title, :text, :locale]]) end end end \ No newline at end of file