Forum: Ruby on Rails Nested forms, extreme weirdness

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
John S. (Guest)
on 2009-06-03 20:13
I took a look at nested forms a few weeks ago, played with it a bit and
it all seemed fine. Now I need to actually use it and it's blown up in
my face.

I've got in my account.rb

    has_many :subscriptions
    accepts_nested_attributes_for :subscriptions

then in my view

    <% form_for @account do |form| %>
    <% form.fields_for :subscriptions do |subscription_form| -%>
    <% end %>
    <% end %>

Now here's the really really weird thing; the nested form should be
produced and it isn't, but if I change the name from :subscriptions to
anything else, then the form is produced, but of course with wrong names
on the input fields.

Wtf am I doing wrong?

John S.
John S. (Guest)
on 2009-06-03 21:09
Ha! Solved it

I had to create at least one instance of a subscription for an account
before the form would be displayed.

Why it would display the form for symbols other than :subscriptions is
another mystery, which I don't need to worry about.

John S.
This topic is locked and can not be replied to.