9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/controllers/admin/atreides/photos_controller.rb', line 9
def create
if params[:dropbox_path]
puts "Downloading from dropbox..."
start = Time.now
data = dropbox_client.get_file(params[:dropbox_path])
puts "Downloaded in #{Time.now - start}..."
filename = File.basename params[:dropbox_path]
puts "Filename: #{filename}"
else
data = request.body.read
filename = params[:qqfile]
end
extension = File.extname(filename)
basename = File.basename(filename, extension)
tempfile = Tempfile.new([basename, extension], :encoding => data.encoding)
tempfile.write(data)
tempfile.rewind
@photo = end_of_association_chain.new
@photo.image = tempfile
if photoable && photoable.is_a?(Atreides::Feature)
feature = photoable
feature.photo.destroy if feature.photo and feature.photo.photoable.nil?
@photo.features << feature
else
@photo.photoable = photoable
end
super do |success, failure|
success.json { render @photo.to_json }
success.js { render :template => "admin/atreides/photos/create.js.haml", :layout => false, :status => :ok }
success.html { render :template => "admin/atreides/photos/create.js.haml", :layout => false, :status => :ok }
failure.json { render @photo.errors.to_json }
failure.js { render :text => @photo.errors.full_messages.to_sentence }
failure.html { render :text => @photo.errors.full_messages.to_sentence }
end
end
|