rubyonrailsin

A Ruby and Rails talk

Friday, March 12, 2010


Re: [Rails] newbie seek for help about paperclippolymorph

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Hi there,


I'm not a longtime Rails developper so pardon me if misunderstood your pb.
But IMHO, I believe you're looking for a solution to enable multiple records creation through one form.
Why don't you have a look at this short video:
and probably part 2 or 3 as well,

Anyway, it helped me to sort out a rather similar problem

Hope this helps,

Christophe


Le 12 mars 2010 à 11:11, Xianggong a écrit :

Hi All,
     I am new to rails and I need to upload multiple images with  paperclippolymorph , I have a model "scene" like this:    
    
     class Scene < ActiveRecord::Base
        belongs_to :user
        acts_as_polymorphic_paperclip
       #  accepts_nested_attributes_for :assets, :allow_destroy => true
     end

     And the controller  and view :

     class ScenesController < ApplicationController
         
         def create
             @scene = Scene.new(params[:scene])
             respond_to do |format|
                if @scene.save
                   # bla bla ..
                else
                   #  bla bla
                end
             end
         end

     end

     #view:
        <% form_for(@scene, :html => { :multipart => true }) do |f| %>
              <%= f.file_field :data %>  <!-- it's just a single file field, how to enable multiple upload? -->
              <%= f.submit "submit" %>
        <% end %>

      I can upload single image successfully but don't know how to upload multiple, my question is how can I upload multiple image at once? I have tried with fields_for like following and it failed,  does anyone have idea?
      
<% form_for(@scene, :html => { :multipart => true }) do |f| %>
       <% f.fields_for :assets do |asset_field| %>
            <%= asset_field.file_field :data %>
            <%= asset_field.file_field :data %>
       <% end %>
<% end %>


        Any advice is appreciated, thanks

        Regards

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive