Class: Admin::Api::MenusController

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

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/admin/api/menus_controller.rb', line 13

def create
  @menu = Odania::Menu.new(content_params)
  @menu.site_id = @site.id

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

#destroyObject



34
35
36
37
38
39
# File 'app/controllers/admin/api/menus_controller.rb', line 34

def destroy
  @menu.destroy

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

#indexObject



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

def index
  @menus = Odania::Menu.where(site_id: params[:site_id]).order('created_at DESC')
end

#showObject



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

def show
  @widgets = Odania::Widget.where(site_id: @menu.site_id, language_id: @menu.language_id)
end

#updateObject



25
26
27
28
29
30
31
32
# File 'app/controllers/admin/api/menus_controller.rb', line 25

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