Class: IshManager::PhotosController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#basic_auth, #home, #tinymce

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
61
# File 'app/controllers/ish_manager/photos_controller.rb', line 29

def j_create
  if params[:slug]
    gallery = Gallery.unscoped.where( :slug => params[:slug] ).first
    gallery ||= Gallery.unscoped.find params[:slug]
  elsif params[:gallery_id]
    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

  @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 => {
      message: @photo.errors.full_messages.join(", "),
      filename: @photo.photo.original_filename,
    }, status: 400
  end
end

#newObject



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

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

#showObject



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

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


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

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