0
votes

I am using paperclip for avatar uploads on my website.

The problem I am having is that when I set the form to remote => true an accounts avatar is not updated. All other attributes are updated except the avatar.

It works fine when I just use a redirect.

I am using remotipart on my site for remote image uploads. Other parts of my site with image uploads through a remote requests work fine.

I am confused on what I am doing wrong.

This is what I have so far for the controller:

 def update
@account = Account.getAccountById(session[:user])
if @account.update_attributes(params[:account])

else

end
end

In the view:

 <% form_for @account, :html => {:multipart => true}, :remote => true do |f| %>

Appreciate any help.

Thanks,

Brian

Update

I am using remotipart gem.

When I right a conditional statement using remotipart_submitted? it always returns false.

In addition, if I check params[:account][:avatar].blank? with remote true it always returns true.

If I remove remote => true then params[:account][:avatar].blank? returns true or false if the file field has a value or not.

So I am confused on why remote => true is not detecting that the file field has a value.

1

1 Answers

0
votes

The problem is that JavaScript will not let you upload a file via XHR, because it’s considered a security risk. The way to get around it is by creating an iframe, copying the form into that, and submitting it normally within the iframe.

You can do this somewhat automatically by using something like jquery.form.js