fields_for doesn't appear to nest names?

1 view
Skip to first unread message

Eric Schwartz

unread,
Dec 15, 2009, 10:07:08 PM12/15/09
to merb
I am trying to build a simple CRUD application with merb 1.0.15 to
learn how to do things in merb. I have the following views:

----- edit.html.haml ------
.h1 edit existing vehicle

= form_for(@vehicle, :action => resource(@vehicle)) do
= partial :form
= submit "Confirm"

----- _form.html.haml -----
%h2 Maintenance Events
%ol#maintenance_events
= partial "maintenance_event", :with => @vehicle.maintenance_events

----- _maintenance_event.html.haml -----
%li
.event
= fields_for maintenance_event do
= text_field :description

I would expect o have text_fields generated with names like

vehicle[maintenance_events][][description]

if the event was not already in the db, or, if the event was
previously saved,

vehicle[maintenance_events][2][description]

(assuming the maintenance_event id is 2, of course).

Instead, I just see

maintenance_event[description]

I'm sure I'm probably doing something wrong here, since this is the
sort of thing that almost any complex web app using Merb would have
had to have encountered long ago, but I'm not at all sure what exactly
it is I'm missing. I have spent the past two hours or so googling all
over for 'merb form_for', 'merb form_for tutorial', 'merb form_for
example' and the like, and come up with nothing, so I hope you'll
forgive me asking such a basic question.

-=Eric

Tony Mann

unread,
Dec 16, 2009, 11:48:19 PM12/16/09
to me...@googlegroups.com
fields_for is purely for having more than one model in the same form. It is not for nesting. For that, use snusu's nested attributes code (search the list archives for details) or do what I do and just roll your own helpers to specify the field names yourself. Not hard at all and very flexible.

..tony..


--

You received this message because you are subscribed to the Google Groups "merb" group.
To post to this group, send email to me...@googlegroups.com.
To unsubscribe from this group, send email to merb+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/merb?hl=en.



Reply all
Reply to author
Forward
0 new messages