Class: Tandem::ImagesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user

Instance Method Details

#createObject

POST /images POST /images.json



53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/tandem/images_controller.rb', line 53

def create
  respond_to do |format|
    if @image.save
      format.html { redirect_to new_image_path(update_gallery: true), notice: 'Image was successfully created.' }
      format.json { render json: @image, status: :created, location: @image }
    else
      format.html { render action: "new" }
      format.json { render json: @image.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /images/1 DELETE /images/1.json



81
82
83
84
85
86
87
88
# File 'app/controllers/tandem/images_controller.rb', line 81

def destroy
  @image.destroy
  
  respond_to do |format|
    format.html { redirect_to images_url }
    format.json { head :ok }
  end
end

#editObject

GET /images/1/edit



48
49
# File 'app/controllers/tandem/images_controller.rb', line 48

def edit
end

#indexObject

GET /images GET /images.json



10
11
12
13
14
15
# File 'app/controllers/tandem/images_controller.rb', line 10

def index
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @images }
  end
end

#newObject

GET /images/new GET /images/new.json



39
40
41
42
43
44
45
# File 'app/controllers/tandem/images_controller.rb', line 39

def new
  @update_gallery = params['update_gallery'].present?
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @image }
  end
end

#showObject

GET /images/1 GET /images/1.json



19
20
21
22
23
24
# File 'app/controllers/tandem/images_controller.rb', line 19

def show
  respond_to do |format|
    format.html #show.html.erb
    format.json { render json: @image }
  end
end

#thumbObject

GET /images/1/thumb GET /images/1/thumb.json this method is deliberately forgiving to image id’s that don’t exist



29
30
31
32
33
34
35
# File 'app/controllers/tandem/images_controller.rb', line 29

def thumb
  @image = Tandem::Image.find_by_id(params[:id])
  @content = Tandem::Content::Image.new(image: @image)
  respond_to do |format|
    format.html { render layout: nil }# thumb.html.erb
  end
end

#updateObject

PUT /images/1 PUT /images/1.json



67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/tandem/images_controller.rb', line 67

def update
  respond_to do |format|
    if @image.update_attributes(params[:image])
      format.html { redirect_to @image, notice: 'Image was successfully updated.' }
      format.json { head :ok }
    else
      format.html { render action: "edit" }
      format.json { render json: @image.errors, status: :unprocessable_entity }
    end
  end
end