Class: Bootsy::ImagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/bootsy/images_controller.rb', line 21

def create
  @gallery = find_gallery
  @gallery.save! unless @gallery.persisted?
  @image = @gallery.images.new(image_params)

  respond_to do |format|
    if @image.save
      format.json {
        render json: {
          image: image_markup(@image),
          form: new_image_markup(@gallery),
          gallery_id: @gallery.id
        }
      }
    else
      format.json {
        render json: @image.errors,
        status: :unprocessable_entity
      }
    end
  end
end

#destroyObject



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

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

  respond_to do |format|
    format.json {
      render json: { id: params[:id] }
    }

    format.html { redirect_to images_url }
  end
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/bootsy/images_controller.rb', line 5

def index
  @gallery = find_gallery
  @images = @gallery.images

  respond_to do |format|
    format.html # index.html.erb

    format.json do
      render json: {
        images: @images.map {|image| image_markup(image) },
        form: new_image_markup(@gallery)
      }
    end
  end
end