You want to execute multiple inserts in a single response, not
multiple responses. This might work, assuming that the rest of your
code works and that you are using attachments as the relationship
name.

def create
  @project = Project.find(params[:id])

  params[:attachment].each do |key, value|
    if value and !value.blank?
      new_file = Image.new(Hash['uploaded_data' => value])
      new_file.user_id = logged_in_user.id
      @project.attachments << new_file
    end
  end

  respond_to do |format|
    if @project.save
      format.js do
        render :update do |page|
          @project.attachments.each do |file|
            page.insert_html :top, "images", :partial =>
'image', :object => file
          end
        end
      end
    end
  end
end

On Apr 7, 9:45 am, Jack Bauer <rails-mailing-l...@andreas-s.net>
wrote:
> Hi guys and gals.
>
> I don't know how to explain this too well, so I'll try my best and post
> some obviously dysfunctional code (just so you can get the idea of what
> I'm after if my explanation doesn't do it.)
>
> What I want to do is create an upload form that users can upload more
> than one item with. The catch is I want to use ajax to pull off an
> insert_html and update the page showing thumbnail to each file as it's
> added, while the other files are being uploaded. So, let's say I upload
> 3 files, when the first one finishes it's inserted to an unordered list
> (via ajax, without reloading the page while the other two files are
> still uploading), then the next file, then the last file and it ends.
> I've been doing it fine with a single file, but now that I've added
> multiple file uploads that controller style won't work.
>
> Doing something like this, which I figured was a 1,000,000:1 shot at it
> working (of course, it didn't) gives a DoubleRender error which I
> expected:
>
> def create
>   @project = Project.find(params[:id])
>
>   params[:attachment].each do |key, value|
>     if value and value != ''
>       @file = Image.new(Hash['uploaded_data' => value])
>       @file.user_id = logged_in_user.id
>       @file.project_id = @project.id
>
>       respond_to do |format|
>         if @file.save
>           format.js do
>                   responds_to_parent do
>                     render :update do |page|
>                 page.insert_html :top, "images", :partial => 'image',
> :object => @file
>                     end
>                   end
>           end
>         else
>           # etc...
>         end
>       end
>     end
>   else
>     # etc.
>   end
>
> Can this sort of thing even be pulled off?
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to