Class: Wco::PhotosController
Instance Method Summary
collapse
#home, #tinymce
#my_truthy?, #obfuscate, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date
Instance Method Details
#destroy ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/controllers/wco/photos_controller.rb', line 10
def destroy
authorize! :destroy, Wco::Photo
if params[:id]
@photos = [ Wco::Photo.unscoped.find( params[:id] ) ]
elsif params[:ids]
@photos = Wco::Photo.where( :id.in => params[:ids] )
end
outs = []
@photos.map do |photo|
photo.gallery.touch if photo.gallery
outs.push photo.delete
end
flash_notice "Outcomes: #{outs}"
redirect_to request.referrer || root_path
end
|
#index ⇒ Object
26
27
28
29
|
# File 'app/controllers/wco/photos_controller.rb', line 26
def index
authorize! :index, Wco::Photo
@photos = Wco::Photo.where( user_profile: @current_profile ).page( params[:photos_page] )
end
|
#j_create ⇒ Object
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
62
63
|
# File 'app/controllers/wco/photos_controller.rb', line 31
def j_create
if params[:slug]
gallery = Wco::Gallery.unscoped.where( :slug => params[:slug] ).first
gallery ||= Wco::Gallery.unscoped.find params[:slug]
elsif params[:gallery_id]
gallery = Wco::Gallery.unscoped.find( params[:gallery_id] )
gallery ||= Wco::Gallery.unscoped.where( :slug => params[:gallery_id] ).first
end
authorize! :create_photo, gallery
@photo = Wco::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
|
#move ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/controllers/wco/photos_controller.rb', line 65
def move
authorize! :move, Wco::Photo
photos = Wco::Photo.where({ :id.in => params[:ids] })
if params['delete'] == '1'
flash_notice 'deleting'
flag = photos.map &:delete
else
flag = photos.update_all({ gallery_id: params[:gallery_id] })
flash_notice 'moving'
end
flash_notice flag
redirect_to request.referrer
end
|
#new ⇒ Object
80
81
82
83
|
# File 'app/controllers/wco/photos_controller.rb', line 80
def new
authorize! :new, Wco::Photo
@photo = Wco::Photo.new
end
|
#show ⇒ Object
85
86
87
88
|
# File 'app/controllers/wco/photos_controller.rb', line 85
def show
@photo = Wco::Photo.unscoped.find params[:id]
authorize! :show, @photo
end
|
#without_gallery ⇒ Object
90
91
92
|
# File 'app/controllers/wco/photos_controller.rb', line 90
def without_gallery
@photos = Wco::Photo.unscoped.where( :gallery => nil, :is_trash => false )
end
|