Class: Admin::Api::MenuItemsController

Inherits:
Admin::ApiController
  • Object
show all
Defined in:
app/controllers/admin/api/menu_items_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/admin/api/menu_items_controller.rb', line 12

def create
	@menu = Odania::Menu.where(site_id: params[:site_id], id: params[:menu_id]).first
	bad_api_request('invalid_menu') if @menu.nil?

	@menu_item = Odania::MenuItem.new(content_params)
	@menu_item.target_data = odania_target_data_params
	@menu_item.menu_id = @menu.id

	if @menu_item.save
		if @menu.default_menu_item_id.nil? and @menu_item.published
			@menu.default_menu_item_id = @menu_item.id
			@menu.save
		end

		flash[:notice] = t('created')
		render action: :show
	else
		render json: {errors: @menu_item.errors}, status: :bad_request
	end
end

#destroyObject



43
44
45
46
47
48
# File 'app/controllers/admin/api/menu_items_controller.rb', line 43

def destroy
	@menu_item.destroy

	flash[:notice] = t('deleted')
	render json: {message: 'deleted'}
end

#indexObject



5
6
7
# File 'app/controllers/admin/api/menu_items_controller.rb', line 5

def index
	@menu_items = Odania::MenuItem.where(menu_id: params[:menu_id]).order('title ASC')
end

#initial_dataObject



50
51
# File 'app/controllers/admin/api/menu_items_controller.rb', line 50

def initial_data
end

#set_defaultObject



53
54
55
56
57
58
59
# File 'app/controllers/admin/api/menu_items_controller.rb', line 53

def set_default
	@menu.default_menu_item_id = @menu_item.id
	@menu.save!

	@menu_items = Odania::MenuItem.where(menu_id: @menu.id).order('title ASC')
	render action: :index
end

#showObject



9
10
# File 'app/controllers/admin/api/menu_items_controller.rb', line 9

def show
end

#updateObject



33
34
35
36
37
38
39
40
41
# File 'app/controllers/admin/api/menu_items_controller.rb', line 33

def update
	@menu_item.target_data = odania_target_data_params
	if @menu_item.update(content_params)
		flash[:notice] = t('updated')
		render action: :show
	else
		render json: {errors: @menu_item.errors}, status: :bad_request
	end
end