开发者

Using Ruby On Rails 2.3, is it possible to accept nested attributes in one form using ActiveResource?

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?


You don't need to use a build method, try this:

3.times { @profile.photos << Photo.new }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜