On 24 December 2011 07:18, Bob Smith wrote:
On Dec 20, 3:53 am, Colin Law wrote:
On 20 December 2011 07:03, Bob Smith wrote:

I'm doing a list of family members, each with aradiobutton for head
of household. After the household record and the records for each
person are created, it is easy to set the hoh field to the person
wanted. The problem comes if I try to set this field before the
create. Then the field is 0, and this isn't updated after the record
is created.
Show us how you are setting the field, presumably increatein the controller.

I was using a variable called hoh in the household (master) record.
This was holding the id number of the person (child) record selected.
This worked fine for existing records, but got lost with records
created at the time of the save, as these records had no id yet.

Someone else suggested that I put the hoh variable in the person
records, but if I do this, each radio button is separate, and there is
no way to allow only one selection.

It seems to me that there must be a way to do this with Active Record
Callbacks. After the record is created, it has an id. Couldn't I test
each person record after create, and if it has the radio button
selected, pass the id to the Household.hoh variable..

But for this... Is there a way to tell if the radio button is selected
if it points to a variable somewhere else ?? Or is there a way to get
Rails to just do this at the right time the way it does with parent/
child records, setting all id's and parent_id's ??
I am sorry but I have not much idea of what you are talking about.
The first thing to do is to split up the problem into the Model, View
Controller paradigm. You are mixing them up talking about things like
ActiveRecord callbacks looking at radio buttons for example. Radio
buttons are meaningless when you are talking about database records,
they are only meaningful in views and controllers.

So the first question to consider is what data do you need in the
database and what are the relationships between the models (has_many,
belongs_to etc). Only when you have got that straight then worry
about how to implement the views and controllers to give the user
interface that you want.

So do you know what is in the database and what the relationships are?
If so give us that information and then explain what the problem is.


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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 11 | next ›
Discussion Overview
grouprubyonrails-talk @
postedDec 20, '11 at 7:04a
activeJan 17, '12 at 5:48a



site design / logo © 2022 Grokbase