Class: PhotosController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/photos_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @resource = params[:model].classify.constantize.find params[:model_id]
  @photo    = @resource.photos.build(remote_image_url: params[:photo])
   
  respond_with(@photo) do |format|
    if @photo.save
      format.json{ render json: @photo  }
      format.js  { render partial: '/layouts/lol_multiple_uploads/photo', locals: { photo: @photo, photo_version: params[:photo_version] } }
    else
      format.json{ render nothing: true, status: :error }
    end
  end
rescue Exception
  render nothing: true, status: :error
end

#destroyObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/photos_controller.rb', line 32

def destroy
  @photo = Photo.find params[:id]
  
  respond_with(@photo) do |format|
    if @photo.destroy
      format.json{ render json: @photo }
    else
      format.json{ render nothing: true, status: :error }
    end
  end
end

#updateObject



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

def update
  @photo = Photo.find params[:id]
   
  respond_with(@photo) do |format|
    if @photo.update_attributes(params[:photo])
      format.json{ render json: @photo  }
    else
      format.json{ render nothing: true, status: :error }
    end
  end
end