Class: OCms::ImagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/o_cms/images_controller.rb', line 28

def create
  @image = Image.new(image_params)

  if @image.save
    flash[:notice] = "Image was saved successfully."
    redirect_to @image
  else
    flash.now[:alert] = "Error creating image. Please try again."
    render :new
  end
end

#destroyObject



57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/o_cms/images_controller.rb', line 57

def destroy
  @image = Image.find(params[:id])

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

#editObject



40
41
42
# File 'app/controllers/o_cms/images_controller.rb', line 40

def edit
  @image = Image.find(params[:id])
end

#indexObject



6
7
8
9
10
11
12
13
# File 'app/controllers/o_cms/images_controller.rb', line 6

def index
  @images = Image.all

  respond_to do |format|
    format.html
    format.js
  end
end

#newObject



24
25
26
# File 'app/controllers/o_cms/images_controller.rb', line 24

def new
  @image = Image.new
end

#showObject



15
16
17
18
19
20
21
22
# File 'app/controllers/o_cms/images_controller.rb', line 15

def show
  @image = Image.find(params[:id])

  respond_to do |format|
    format.html
    format.js
  end
end

#updateObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/o_cms/images_controller.rb', line 44

def update
  @image = Image.find(params[:id])
  @image.assign_attributes(image_params)

  if @image.save
    flash[:notice] = "Image was updated successfully."
    redirect_to @image
  else
    flash.now[:alert] = "Error saving image. Please try again."
    render :edit
  end
end