Class: IshManager::PhotosController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/photos_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home

Instance Method Details

#destroyObject

Alphabetized : )



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/ish_manager/photos_controller.rb', line 10

def destroy
  @photo = Photo.unscoped.find params[:id]
  authorize! :destroy, @photo
  @photo.gallery.touch if @photo.gallery
  @photo.is_trash = true
  flag = @photo.save
  if flag
    flash[:notice] = "Success"
  else
    flash[:alert] = "No luck: #{@photo.errors.messages}"
  end
  redirect_to request.referrer || root_path
end

#indexObject



24
25
26
27
# File 'app/controllers/ish_manager/photos_controller.rb', line 24

def index
  authorize! :index, Photo
  @photos = Photo.where( user_profile: @current_profile ).page( params[:photos_page] )
end

#j_createObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/ish_manager/photos_controller.rb', line 29

def j_create
  # find this gallery
  if params[:slug]
    gallery = Gallery.unscoped.where( :slug => params[:slug] ).first
    gallery ||= Gallery.unscoped.find params[:slug]
  elsif params[:gallery_id] # this one, let's normalize on id everywhere in manager.
    gallery = Gallery.unscoped.find( params[:gallery_id] )
    gallery ||= Gallery.unscoped.where( :slug => params[:gallery_id] ).first
  end
  authorize! :create_photo, gallery

  @photo = Photo.new params[:photo].permit!
  @photo.is_public = true
  @photo.gallery = gallery

  # cache
  @photo.gallery.touch

  if @photo.save
    j = {
      :name => @photo.photo.original_filename,
      :size => @photo.photo.size,
      :url => @photo.photo.url( :large ),
      :thumbnail_url => @photo.photo.url( :thumb ),
      :delete_url => photo_path(@photo),
      :delete_type => 'DELETE'
    }
    render :json => [ j ]
  else
    render :json => { "errors" => @photo.errors }
  end
end

#newObject



62
63
64
65
# File 'app/controllers/ish_manager/photos_controller.rb', line 62

def new
  authorize! :new, Photo
  @photo = Photo.new
end

#showObject



67
68
69
70
# File 'app/controllers/ish_manager/photos_controller.rb', line 67

def show
  @photo = Photo.unscoped.find params[:id]
  authorize! :show, @photo
end


72
73
74
# File 'app/controllers/ish_manager/photos_controller.rb', line 72

def without_gallery
  @photos = Photo.unscoped.where( :gallery => nil, :is_trash => false )
end