I have been using rails professionally for only a month and a half now,
but I am continually running into problems with form helpers and
accessing multiple objects on a single page. To whit:
-
While text_field and text_area and such all support the :index
option, the select helper does not. -
When appending the text ‘[]’ to a helper’s object name, the id is
inserted into the brackets — but only for existing objects. While it
is understandably difficult as new objects have no ids, a method must
exist somewhere to provide these form helpers with a unique way to
communicate their unique data to their responding controllers. One
suggestion is to create the option to specify the object attribute that
will be used to fill the '[]'s. The example for which I’m having to work
around this is an administrative form to generate promotional contact
forms. These forms each have up to 6 questions and each question can
have up to 4 answers. Thus in the model, Promo has_many PromoQuestion
which has_many PromoAnswer. So I am dealing with having to iterate over
three levels of hierarchical data both in the edit form and in the
creation form. It does not seem Rails is designed to handle this type of
form terribly simply. While I understand that this type of form is
possible, its implementation seems far from elegant. -
Rails hierarchical model objects seem to support the creation of a
tree of new objects that can then be saved with @parent.save. But
modifying this same tree afterwards does not. Should there not be a way
to modify attributes of existing child objects and mark them as “to be
saved” so that when @parent.save is called to update the parent, all the
child objects are also updated? This does not seem to be the case, as I
experienced with the self-same promo example above. Calling @parent.save
after modifying @parent.child.attributes = {…} does not save the
modifications to the child.
Perhaps there are undocumented features of which I am not aware. If this
is the case, then my issue becomes one with the documentation.
And perhaps I just do not understand the elegant way to perform such
tasks as those above. If so, I am eager to learn, and would greatly
appreciate being pointed to the appropriate documentation.