Forum: Ruby on Rails Upload progress problem with Ajax component

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.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-13 17:09
All,

I believe that I've set up an upload progress bar correctly.  When I do
my upload, the initial status message appears on the screen, and when
the upload finishes, the finish message appears on the screen.  However,
in between, the status bar is not updating.  So my progress bar starts
out with 0% filled in, and then, when the upload completes, it's 100%
filled in.

Environment:

Windows XP
WEBrick 1.3.1
Rails 1.0
Prototype 1.4
script.aculo.us 1.5.3

I did some debugging and it appears that the Ajax updater call happens
twice after I initiate the upload action, and then no more calls to
upload_status occur.  However, when the upload completes, then all of
the Ajax updater calls begin to happen per the degradation schedule.
Also, when the save_HTML (the actual upload method) completes, the view
save_HTML.rhtml does not get called.

It's like something gets stuck and doesn't return control back to the
browser when it should and therefore the progress bar can't be updated.

I'm not sure what is wrong here - whether there is a genuine Javascript
problem or whether I am not returning control to my page correctly.
Here are some code snippets

upload.rhtml:
<%= form_tag_with_upload_progress(
   { :action => 'save_HTML' },
   { :begin => 'do_start()',
     :finish => 'do_finish(arguments[0])',
     :frequency => 5 }) %>
  <%= file_field 'eSimplyJob', 'file' %>
  <P>
    <%= submit_tag "Upload" %>
  </P>
  <%= upload_status_tag %>
<%= end_form_tag %>

In my controller: upload_status_for :save_HTML

save_HTML (in controller):
public
  def save_HTML
    @filename = @params[:eSimplyJob][:file].original_filename
    File.open("#{RAILS_ROOT}/htmlfiles/#{@filename}", "wb") do |f|
      f.write(@params[:eSimplyJob][:file].read)
    end
    puts "Finished with save_HTML"
  end

upload_status (in controller):
public
  def upload_status
    puts 'Called upload status...'
    render  :inline => "<script><%= upload_progress_update_bar_js
%></script>",
            :layout => false
  end
This topic is locked and can not be replied to.