Forum: Ruby on Rails jquery and accepts_nested_attributes_for model creation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
yaphi (Guest)
on 2009-02-22 01:40
(Received via mailing list)
I am getting lost in dynamically creating Asset objects while creating
a new Project. I am using the new accepts_nested_attributes_for method
in Rails 2.3 and have this close to working, I just can't figure out
what my custom controller method "add_asset" should be doing here. I
am using jQuery instead of Prototype.

Here is the relevant code:
http://pastie.org/private/oom26fy67vkahsamjpvg

I know that the new asset isn't getting built, and I need to do that
in the add_asset controller action, but I also don't know how to
generate a file_field for that object whenever it's created.

Right now the file_field that's getting generated using nested_for is:

<input id="project_assets_attributes_new_1_asset" type="file"
size="30" name="project[assets_attributes][new_1][asset]"/>

but my input field from the add_asset controller method is:

<input id="project_assets" type="file" size="30" name="project
[assets]"/>

Any help would be appreciated. I've been staring at this all day long!
Remy E. (Guest)
on 2009-04-03 03:16
I have the same problem, any idea ?


yaphi wrote:

> Here is the relevant code:
> http://pastie.org/private/oom26fy67vkahsamjpvg
>
> I know that the new asset isn't getting built, and I need to do that
> in the add_asset controller action, but I also don't know how to
> generate a file_field for that object whenever it's created.
> ...
>
> Any help would be appreciated. I've been staring at this all day long!
This topic is locked and can not be replied to.