完成上传头像功能
This commit is contained in:
parent
a95c79cd6c
commit
54bdaec347
|
@ -53,7 +53,19 @@ class BlogsController < ApplicationController
|
|||
end
|
||||
|
||||
def upload_img
|
||||
|
||||
@result = {status: false, message: '', text_id: params[:upload][:text_id] || ''}
|
||||
begin
|
||||
if params[:upload].present? && params[:upload][:img].present? && remotipart_submitted?
|
||||
upload_info = upload_picture params[:upload][:img]
|
||||
@result[:status] = true
|
||||
@result[:message] = "![#{upload_info[:file_name]}](/images/#{upload_info[:real_file_name]})"
|
||||
end
|
||||
rescue UploadException => e
|
||||
@result[:message] = e.message
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def preview
|
||||
|
@ -68,6 +80,8 @@ class BlogsController < ApplicationController
|
|||
protected
|
||||
|
||||
def upload_picture(file)
|
||||
|
||||
upload_path = File.join Rails.root, 'public/images'
|
||||
upload = SimpleFileupload.new upload_path:upload_path, max_size: 1024*1024*2, type: 'image'
|
||||
upload_info = upload.upload file
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
- if @result[:status]
|
||||
:plain
|
||||
var old_val = $("##{@result[:text_id]}").val();
|
||||
$("##{@result[:text_id]}").val(old_val + "#{@result[:message]}");
|
||||
$('#upload_modal').modal('hide');
|
||||
- else
|
||||
:plain
|
||||
$('#error').text("#{@result[:message]}");
|
Loading…
Reference in New Issue