Thanks Rick,

After I read your post and looked for the nth time at the
documentation I finally "saw" a couple of things that I had completely
misunderstood. I still need help, though. I’ll try to explain as best
as possible.

-       The application uses a legacy DB
-       A person has many person_projects (1 to n)
-       A person_project has one project
-       A person_project has one supervisor
-       A project contains a group code (this is important, the projects are
selected by the group code)
-       A project has one supervisor (1)
-       A project has many contractors (0 to n)
-       A contractor has one supervisor (1)
-       A supervisor is not a person, meaning his/her data is not in the
same table as a person’s data (remember, this is a legacy DB)
-       The application is “wizard” style and the same pages are used for
create/update
-       The information should not be changed/created until the last page of
the “wizard” is hit, which fortunately is the page used to select the
information for the person_project records

In a first page the user selects the group codes and that list will
provide all the projects a person should have person_projects for.
Once the group codes are selected the next page should display a table/
list of the projects. If the person record already exists this list
might match exactly the current person_projects list and/or contain
different projects and/or… every possible combination. In addition to
that for each project there should be a drop down of supervisors to
choose from composed of:

-       The current person_project supervisor if the person_project record
exists
-       The project supervisor (the supervisor ID stored in the
person_project record could be different [wrong or most likely empty]
than what the project record indicates should be)
-       All the supervisors for the project contractors

The person_project table should be updated by:

-       Removing any record from the person_projects table not on the
selected list
-       Updating the signatory IDs in those existing person_project records
where they have changed
-       Adding new records for any projects not yet in the person_project
table

Unfortunately I am not as comfortable with Rails yet as I would like
to be and I have been working on this on and off for more than 2 weeks
now. I have hit every possible page (many times) I could find with
information about complex forms and multi record processing, watched
the railscasts, hit the books, everything… Depending on the approach I
take sometimes validations are skipped or new person_project records
are not saved, or… I’ve hit every possible roadblock.

If you guys know how to solve this riddle I would be very, very
thankful.

Thanks a lot.


On Jan 9, 10:43 pm, Rick DeNatale <[email protected]> wrote:
> On Sat, Jan 9, 2010 at 9:19 PM, pepe <[email protected]> wrote:
> > I am just learning how to use 'fields_for' so forgive me if I sound
> > like I don't know what I'm talking about.
>
> > My understanding is that 'fields_for' will iterate through the
> > collection, hence working with one element/object of the collection in
> > each iteration. If I need an attribute from the element/object at each
> > iteration, how would I know which element to access with
> > @my_object.my_collection? I don't even know if there is an index I can
> > use to get to the element I need as in @my_object.my_collection
> > [my_index], hence allowing me to do something like:
>
> No fields_for doesn't do any iteration. It's used for setting up a
> scope for one or more form fields for a different object than the one
> which scopes an outer form_for
>
> From the doc:
>
> <% form_for @person, :url => { :action => "update" } do |person_form| %>
>     First name: <%= person_form.text_field :first_name %>
>     Last name : <%= person_form.text_field :last_name %>
>
>     <% fields_for :person do |permission_fields| %>
>        Admin?: <%= permission_fields.check_box :admin %>
>     <% end %>
>  <% end %>
>
> So just like form_for doesn't do any iteration, neither does fields_for.
>
> Since you haven't told us any more about what you want to do, I don't
> know how to help any further.
>
> --
> Rick DeNatale
>
> Blog:http://talklikeaduck.denhaven2.com/
> Twitter:http://twitter.com/RickDeNatale
> WWR:http://www.workingwithrails.com/person/9021-rick-denatale
> LinkedIn:http://www.linkedin.com/in/rickdenatale
-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to