Hi Everyone–
First the details…I have two models at the moment, member and
account, which have the following relationship:
class Member < ActiveRecord::Base
Relationship between member and account
has_one :account
end
class Account < ActiveRecord::Base
Relationship between account and member
belongs_to :member
end
Member has a bunch of attributes (first_name, last_name, address, etc.),
and account has user_name, password, and email.
An administrator will create the members, and members will not be
allowed to create their own accounts initially. But that functionality
may be needed later on so it seemed like a good idea to keep them
separate.
Now for the questions.
I have created a form for adding new members and it works fine. But how
would I set the values of the account with a user_name (first letter of
first name + lastname), and email address (which would be included in
the form but is not an attribute of member)? I have watched the
projects/tasks railscast several times on how to deal with multiple
models in one form, but I don’t quite get it…like how to use the
“fields_for” without a for loop and the whole ‘builds’ concept. Is that
functionality a standard part of rails? Every resource I’ve come across
regarding forms and multiple models points to that same example, so it
really isn’t helping much.
Unfortunately this is the most complicated part of my application, but I
really need to get this working. Any suggestions would be greatly
appreciated, including ‘you should not do it that way, it’s better
to…’.
Thanks,
Damonica