Fields_for weirdness

I just did a large upgrade to to Rails 2.3.4 and I am trying to make
use of the more modern view features.

I have a Newsletter object. Newsletter has many Sections.

I also have:

accepts_nested_attributes_for :sections

on the Newsletter object.

I have the typical scaffolded new.html.erb with:

<% form_for(@newsletter) do |f| %>

in there, I am trying to populate the first Section using fields_for
during the newsletter creation.
If I try to emphasize “sections” in fields_for , I get an exception.

Otherwise, I can do this:

<% f.fields_for :section, :index => 0 do |s| %>

which in the forms creates newsletter[section][0].

It will recognize :section but not :sections.

If I manually set it so that it comes out as
newsletter[sections][0]
I get a “Section expected but got Array”

I have tried with and without the section index.

Any ideas? This is should be a text book usage and I am out of ideas
to get it working.

thanks,
C.

of course… i post here and then I get it .

I started getting angry and thrashing and put the
@newsletter.sections.build in the wrong method.
once i moved it, everything started working just fine.

thanks,
C.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs