Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jandudulski
Created July 18, 2012 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jandudulski/3135903 to your computer and use it in GitHub Desktop.
Save jandudulski/3135903 to your computer and use it in GitHub Desktop.
IE json bug
class PhotosController < ApplicationController
before_filter :authenticate_user!
def create
current_user.photo = params[:file] || params[:qqfile]
data = if current_user.save
{
:success => true,
:photo => {
:original => current_user.photo.url,
:avatar => current_user.photo.avatar.url
}
}
else
current_user.errors
end
respond_to do |format|
format.json {
render :json => "#{data.to_json}", :content_type => 'text/html'
}
end
end
end
%div.field.avatar
- if current_user.photo.present?
= image_tag current_user.photo.avatar.url, :id => 'original_photo'
#upload{ :data => { :source => photo_path } }
= f.file_field :photo
// with: https://github.com/valums/file-uploader
$(function() {
var createUploader = function() {
var $elem = $('#upload'), params = {};
params[$('[name=csrf-param]').attr('content')] = $('[name=csrf-token]').attr('content');
params['format'] = 'json';
var uploader = new qq.FileUploader({
element: $elem[0],
action: $elem.data('source'),
debug: false,
onComplete: function(id, filename, responseJSON) {
if (responseJSON.success) {
$('#original_photo').attr('src', responseJSON['photo']['avatar']);
}
}
});
uploader.setParams(params);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment