Provide feedback for viewing from the controller

I am using multiple file fields to view multiple files. I would like to inform the user about the loading progress . I tried using something like this

def create  
    params[:upload_data].each do |file|  
    unless (file =="" or file== nil)   
    @photo = Photo.create({:approved => false, :user_id => @current_user.id})    
        @result = "Uploading #{file.original_filename}"  
            render :update do |page|  
            page.insert_html(:bottom, 'progress', :partial => 'partials/result')   
            end   
         #... perform upload
end

      

It works great if I remove user feedback. However, it fails with multiple render errors when it is found. I was wondering if anyone knows about this.

+1


a source to share


3 answers


You cannot call render multiple times. Render should only be used when returning a controller method.

To get this to work you will need to change the way the requests are made, possibly using ajax. Then each download will update something on the page, and javascript will make the next call to "download this file and then update".



Edit: I'm not a proponent, so I can't give you an actual working code for this, but it would be something like this. You are currently sending multiple files as parameters to the controller. You need to change this so that the backend only processes one file at a time. This means changing the interface to make separate requests to the backend. You cannot do this with just an html form - you need javascript. The controller will render rjs to send the updated "rendered xyz file", the client side code will disable the other upload until all files have been downloaded.

+2


a source


I've used this with great success: SWFUpload



This is the flash control that does the loading, you provide the html interface whether you are using text or% bar.

+1


a source


If you are using Workling as a work background, it can store information about the work progress, which can then be used to update the progess panel on your page using javascript.

+1


a source







All Articles