Forum: Ruby on Rails How to upload file by ajax

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Nuugii L. (Guest)
on 2008-12-08 10:32
Hey'
How to upload file with ajax in ROR?
My code not working :(
View file :
<% form_remote_tag(:url => { :controller => 'Upload', :action =>
'uploadFile'},
          :update => "result",
          :position => :bottom
           :html => {:multipart => true} ) do %>
    <p><label for="upload_file">Choose file :</label> :
    <%= file_field 'upload', 'datafile', :size => '60' %></p>
    <%= submit_tag "Upload" %>
    <% end %>

Controller :
def uploadFile
   @post = DataFile.save( params[:upload])
   if @post
     render :partial => 'data', :object => @post
   end
end
Frederick C. (Guest)
on 2008-12-08 10:55
(Received via mailing list)
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
This topic is locked and can not be replied to.