done: function(e, data){
data.context.removeClass('working');
response = data.jqXHR.responseJSON;
if (response.status == "error"){
data.context.addClass('error');
data.context.append('<i class="msg">'+response.msg+'</i>');
}
else{
data.context.append('<i class="msg">Фото загружено</i>');
data.context.append('<img src="'+response.msg+'"</img>');
}
},
def upload
response = {:status => nil, :msg => nil}
begin
if current_user.attachments.count>=10
raise UserException, "Превышено максимальное количество файлов."
end
attach = Attachment.new
attach.pic = params[:file]
attach.user = current_user
attach.save!
if attach.errors.empty?
response[:status]="success"
response[:msg] = attach.pic.thumb.url
render json: JSON.generate(response)
else
raise UserException, "Фото не добавлено."
end
rescue UserException => e
response[:status] = "error"
response[:msg] = e.message
render json: JSON.generate(response)
rescue Exception => e
response[:status] = "error"
response[:msg] = "Фатальная ошибка. "
response[:msg] << e.message if Rails.env.development?
render json: JSON.generate(response)
rescue
response[:status] = "error"
response[:msg] = "Фатальная ошибка."
render json: JSON.generate(response)
end
end
{
"status":"succsess"
}
done: function(e, data){
data.context.removeClass('working');
response = data.jqXHR.responseJSON;
if (response.status == "error"){
data.context.addClass('error');
data.context.append('<i class="err-msg">'+response.msg+'</i>');
}
},
def upload
begin
attach = Attachment.new
attach.pic = params[:file]
attach.user = current_user
attach.save!
render json: '{"status":"success"}'
rescue
render json: '{"status":"error","msg":"Ошибка обработки файла."}'
end
end