0

I have a Profile -> Photo relationship on the "server" application. The client application would the ability to upload up to three photos to the server side.

A side note: I am using Paperclip plugin on the serving app.

I have done something like this successfully with a one-to-one relationship but never with a has_many.

Naturally, ActiveResource does not have the build method.

How can each Photo be initialized?

3.times{@profile.photos.build} 

will not work

How will this be accomplished in the view also? I was considering manually coding 3 file_fields naming each one. e.g.

    <%= file_field_tag 'profile[photos_attributes][0][data]' %>
    <%= file_field_tag 'profile[photos_attributes][1][data]' %>
    <%= file_field_tag 'profile[photos_attributes][2][data]' %>

would I need a fields_for block for each photo instance?

Long story short, how do I successfully initialize/accept the form data for Profile and its child model, Photo?

4

1 回答 1

0

你不需要使用build方法,试试这个:

3.times { @profile.photos << Photo.new }
于 2010-11-18T21:09:48.103 回答