How to upload file by ajax


#1

Hey’
How to upload file with ajax in ROR?
My code not working :frowning:
View file :
<% form_remote_tag(:url => { :controller => ‘Upload’, :action =>
‘uploadFile’},
:update => “result”,
:position => :bottom
:html => {:multipart => true} ) do %>

Choose file : :
<%= file_field ‘upload’, ‘datafile’, :size => ‘60’ %>


<%= submit_tag “Upload” %>
<% end %>

Controller :
def uploadFile
@post = DataFile.save( params[:upload])
if @post
render :partial => ‘data’, :object => @post
end
end


#2

On Dec 8, 8:32 am, Nurzed L. removed_email_address@domain.invalid
wrote:

Hey’
How to upload file with ajax in ROR?

You can’t, because javascript doesn’t have access to the filesystem.
There’s a trick you can play with an invisible iframe, you should be
able to find it with a quick google.

Fred