Class: Guts::SitesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Guts::SitesController
- Defined in:
- app/controllers/guts/sites_controller.rb
Overview
Sites controller
Instance Method Summary collapse
-
#create ⇒ Object
Creates a site through post.
-
#destroy ⇒ Object
Destroys a site.
-
#edit ⇒ Object
Editting of a site.
-
#index ⇒ Object
Displays a list of sites.
-
#new ⇒ Object
Creation of a site.
-
#remove_default ⇒ Object
Removes a site as default.
-
#set_default ⇒ Object
Sets a site as default.
-
#show ⇒ Object
Shows detaisl about a single site.
-
#update ⇒ Object
Updates a site through patch.
Instance Method Details
#create ⇒ Object
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 41 |
# File 'app/controllers/guts/sites_controller.rb', line 31 def create @site = Site.new site_params @site if @site.save flash[:notice] = 'Site was successfully created.' redirect_to sites_url else render :new end end |
#destroy ⇒ Object
Note:
Redirects to #index on success
Destroys a site
58 59 60 61 62 |
# File 'app/controllers/guts/sites_controller.rb', line 58 def destroy @site @site.destroy redirect_to sites_url, notice: 'Site was successfully destroyed.' end |
#edit ⇒ Object
Editting of a site
25 26 27 |
# File 'app/controllers/guts/sites_controller.rb', line 25 def edit @site end |
#index ⇒ Object
Displays a list of sites
9 10 11 |
# File 'app/controllers/guts/sites_controller.rb', line 9 def index @sites = policy_scope(Site).all end |
#new ⇒ Object
Creation of a site
19 20 21 22 |
# File 'app/controllers/guts/sites_controller.rb', line 19 def new @site = Site.new @site end |
#remove_default ⇒ Object
Removes a site as default
78 79 80 81 82 83 84 |
# File 'app/controllers/guts/sites_controller.rb', line 78 def remove_default @site, :update? @site.update(default: false) flash[:notice] = 'Site was successfully changed to not default.' redirect_to sites_url end |
#set_default ⇒ Object
Sets a site as default
65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/guts/sites_controller.rb', line 65 def set_default @site, :update? old_default = Site.find_by(default: true) old_default.update({ default: false }) unless old_default.nil? @site.update(default: true) flash[:notice] = 'Site was successfully set to default.' redirect_to sites_url end |
#show ⇒ Object
Shows detaisl about a single site
14 15 16 |
# File 'app/controllers/guts/sites_controller.rb', line 14 def show @site end |
#update ⇒ Object
Note:
Redirects to #index if successfull or re-renders #edit if not
Updates a site through patch
45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/guts/sites_controller.rb', line 45 def update @site if @site.update site_params flash[:notice] = 'Site was successfully updated.' redirect_to sites_url else render :edit end end |