Class: Admin::Api::SitesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @site = Odania::Site.new(site_params)
  @site.is_default = true if Odania::Site.where(is_default: true).count == 0

  if @site.save
    update_languages

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

#destroyObject



37
38
39
40
41
42
# File 'app/controllers/admin/api/sites_controller.rb', line 37

def destroy
  @site.destroy

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

#indexObject



4
5
6
# File 'app/controllers/admin/api/sites_controller.rb', line 4

def index
  @sites = Odania::Site.order('name ASC')
end

#showObject



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

def show
  @widgets = Odania::Widget.where(site_id: @site.id)
end

#updateObject



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/admin/api/sites_controller.rb', line 26

def update
  if @site.update(site_params)
    update_languages

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