Class: RubberRing::AttachmentsController
Instance Method Summary
collapse
Methods included from Util
get_attachment_directories, get_options_from_params, load_attachments_page, move_file, save_file_to_fs, save_page_content
#build, #load_page_content, #publish, #respond, #set_locale
Instance Method Details
#add ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/rubber_ring/attachments_controller.rb', line 28
def add
name = params[:file].original_filename
temp_dir = 'public/upload/temp'
Util.save_file_to_fs(temp_dir, name, params[:file].read)
uploaded_file_path = File.join(temp_dir, name)
dir_config = Util.get_attachment_directories(params)
type = FastImage.type(uploaded_file_path).nil? ? 'file' : 'image'
dir, src_dir = "#{type}_dir", "#{type}_src_dir"
Util.move_file(uploaded_file_path, dir_config[dir])
render :json => { src: '/' + File.join(dir_config[src_dir], name), type: type }
end
|
#convert_image(path, width, height) ⇒ Object
18
19
20
21
|
# File 'app/controllers/rubber_ring/attachments_controller.rb', line 18
def convert_image(path, width, height)
image = ImageSorcery.new(path)
image.convert(path, quality: 90, resize: "#{width}x#{height}>")
end
|
#remove ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'app/controllers/rubber_ring/attachments_controller.rb', line 43
def remove
unless params[:src_to_remove].blank?
file_to_remove = "public/#{params[:src_to_remove]}"
FileUtils.rm(file_to_remove)
end
render :json => { src: params[:src_to_remove] }
end
|
#save_attachment ⇒ Object
23
24
25
26
|
# File 'app/controllers/rubber_ring/attachments_controller.rb', line 23
def save_attachment
page = Util.save_page_content(params)
respond(page)
end
|
#save_image ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'app/controllers/rubber_ring/attachments_controller.rb', line 5
def save_image
page = Util.save_page_content(params)
width, height = params[:width], params[:height]
unless width.nil? and height.nil?
key = params[:content].keys.first
path = "public/#{page.content[key]}"
convert_image(path, width, height) if File.exist?(path)
end
respond(page)
end
|