Created
July 18, 2012 12:25
-
-
Save jandudulski/3135903 to your computer and use it in GitHub Desktop.
IE json bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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