Class: Sibu::SitesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sibu/sites_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
# File 'app/controllers/sibu/sites_controller.rb', line 21

def create
  @site = Sibu::Site.new(site_params)
  if @site.save_and_init
    redirect_to sites_url, notice: "Le site a bien été créé."
  else
    flash.now[:alert] = "Une erreur s'est produite lors de la création du site."
    render :new
  end
end

#destroyObject



44
45
46
47
# File 'app/controllers/sibu/sites_controller.rb', line 44

def destroy
  @site.destroy
  redirect_to sites_url, notice: "Le site a bien été supprimé."
end

#editObject



31
32
33
# File 'app/controllers/sibu/sites_controller.rb', line 31

def edit
  @next_page = params[:next_page]
end

#indexObject



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

def index
  @sites = Sibu::Site.where(user_id: send(Rails.application.config.sibu[:current_user]).id)
end

#newObject



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

def new
  @site = Sibu::Site.new(user_id: send(Rails.application.config.sibu[:current_user]).id)
end

#showObject



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

def show
  @page = @site.page('')
  redirect_to site_page_path(@site.id, @page.id)
end

#updateObject



35
36
37
38
39
40
41
42
# File 'app/controllers/sibu/sites_controller.rb', line 35

def update
  if @site.update(site_params)
    redirect_to (params[:next_page].blank? ? sites_url : params[:next_page]), notice: "Le site a bien été mis à jour."
  else
    flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement du site."
    render :edit
  end
end