Hi, There is an example for nested file upload form by using paperclip. The codes are similar to you, be attention to the usage of accepts_nested_attributes_for.
Check it here: http://rails-bestpractices.com/posts/45-use-sti-and-polymorphic-model-for-multiple-uploads On Aug 18, 1:43 pm, Tom Mac <[email protected]> wrote: > Hi > My models are message_thread, message, document (document with > attachments I am using paperclip) > > message_thread > ==================== > has_many messages > > message > ============== > belongs_to message_thread > has_many :document_messages > has_many :documents, :through => :document_messages > > document > ============= > has_attached_file :attachment, > :storage => :database > has_many :document_messages > has_many :messages, :through => :document_messages > > What i need is to create a message_thread with one message and that > message with 2(or more) attachments. I tried like > > messages_controller > ====================== > def new > @message_thread = MessageThread.new > @message = @message_thread.messages.build > end > > new.html.erb > ====================== > > <%form_for @message_thread, :url => { :action => "create" },:html => > {:multipart => true,:class => "mail-tenant"} do |f| %> > <p><%= f.text_field :mail_to %></p> > <p> > <% f.fields_for :messages do |message| %> > <%= message.label :subject,'Subject' %> > <%= message.text_field :subject,:maxlength => 255 %> > </p> > <div class="attachments"> > <p><strong>Attachments:</strong></p> > <% message.fields_for :documents do |document| %> > <div class="fileinputs"> > <%= document.file_field :attachment,:class => "file" %> > <%= document.hidden_field :company_id,:value => > current_company.try(:id)%> > </div> > <%end%> <!-- end of f.fields_for :documents --> > <%end%> <!-- end of f.fields_for :messages --> > </div> > <div class="two-button"> > <button type="submit" class="button2"><span>Send</span></button> > </div> > <p>Or <a href="#">Cancel</a></p> > <%end%> <!-- form ends here --> > > But I am getting error > ActiveRecord::AssociationTypeMismatch in MessagesController#create > > Document(#-614356858) expected, got Array(#-608120208) > > Please help me to solve this. I have a vague idea of using > accepts_nested_attributes_for . But please tell here can I use it > > Thanks in advance > > Tom > -- > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

