Class: Guts::SitesController

Inherits:
ApplicationController show all
Includes:
ControllerPermissionConcern
Defined in:
app/controllers/guts/sites_controller.rb

Overview

Sites controller

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Methods included from MultisiteConcern

#current_site, #with_current_site

Instance Method Details

#createObject

Note:

Redirects to #index if successfull or re-renders #new if not

Creates a site through post



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/guts/sites_controller.rb', line 31

def create
  @site = Site.new site_params

  if @site.save
    flash[:notice] = 'Site was successfully created.'
    redirect_to sites_url
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a site



55
56
57
58
# File 'app/controllers/guts/sites_controller.rb', line 55

def destroy
  @site.destroy
  redirect_to sites_url, notice: 'Site was successfully destroyed.'
end

#editObject

Editting of a site



26
27
# File 'app/controllers/guts/sites_controller.rb', line 26

def edit
end

#indexObject

Displays a list of sites



12
13
14
# File 'app/controllers/guts/sites_controller.rb', line 12

def index
  @sites = Site.all
end

#newObject

Creation of a site



21
22
23
# File 'app/controllers/guts/sites_controller.rb', line 21

def new
  @site = Site.new
end

#remove_defaultObject

Removes a site as default



72
73
74
75
76
77
# File 'app/controllers/guts/sites_controller.rb', line 72

def remove_default
  @site.update_attribute(:default, false)

  flash[:notice] = 'Site was successfully changed to not default.'
  redirect_to sites_url
end

#set_defaultObject

Sets a site as default



61
62
63
64
65
66
67
68
69
# File 'app/controllers/guts/sites_controller.rb', line 61

def set_default
  old_default = Site.find_by(default: true)
  old_default.update_attribute(:default, false) unless old_default.nil?

  @site.update_attribute(:default, true)

  flash[:notice] = 'Site was successfully set to default.'
  redirect_to sites_url
end

#showObject

Shows detaisl about a single site



17
18
# File 'app/controllers/guts/sites_controller.rb', line 17

def show
end

#updateObject

Note:

Redirects to #index if successfull or re-renders #edit if not

Updates a site through patch



44
45
46
47
48
49
50
51
# File 'app/controllers/guts/sites_controller.rb', line 44

def update
  if @site.update site_params
    flash[:notice] = 'Site was successfully updated.'
    redirect_to sites_url
  else
    render :edit
  end
end