Class: OCms::GalleriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/o_cms/galleries_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/o_cms/galleries_controller.rb', line 19

def create
  @gallery = Gallery.new(gallery_params)

  if @gallery.save
    flash[:notice] = "Gallery was saved successfully."
    redirect_to edit_gallery_path(@gallery)
  else
    flash.now[:alert] = "Error creating gallery. Please try again."
    render :new
  end
end

#destroyObject



49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/o_cms/galleries_controller.rb', line 49

def destroy
  @gallery = Gallery.find(params[:id])

  if @gallery.destroy
    flash[:notice] = "\"#{@gallery.name}\" was deleted successfully."
    redirect_to action: :index
  else
    flash.now[:alert] = "There was an error deleting the gallery."
    render :show
  end
end

#editObject



31
32
33
34
# File 'app/controllers/o_cms/galleries_controller.rb', line 31

def edit
  @gallery = Gallery.find(params[:id])
  @images = Image.all
end

#indexObject



6
7
8
# File 'app/controllers/o_cms/galleries_controller.rb', line 6

def index
  @galleries = Gallery.all
end

#newObject



14
15
16
17
# File 'app/controllers/o_cms/galleries_controller.rb', line 14

def new
  @gallery = Gallery.new
  @images = Image.all
end

#showObject



10
11
12
# File 'app/controllers/o_cms/galleries_controller.rb', line 10

def show
  @gallery = Gallery.find(params[:id])
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/o_cms/galleries_controller.rb', line 36

def update
  @gallery = Gallery.find(params[:id])
  @gallery.assign_attributes(gallery_params)

  if @gallery.save
    flash[:notice] = "Gallery was updated successfully."
    redirect_to edit_gallery_path(@gallery)
  else
    flash.now[:alert] = "Error saving gallery. Please try again."
    render :edit
  end
end