To populate from a static array or from AR… I had the same quandry and ended up doing it the ‘rails’ way as you describe below. Although as you said, it is such a static thing that might as well use a constant array. The other question is to store M/F in Person.gender or store an integer.
Since rails should be caching the model, I dont think it is a real big difference performance-wise either way. I think it probably comes down to your aesthetics, what feels right and what looks best to you.
To populate from a static array or from AR.... I had the same quandry
According to the way I think, a model object is something you CURD
(create, update, read, or delete). Unless you're God you're not going to
be creating or deleting genders.
I'd go with a static enumeration (Male, Female or M, F or 0, 1). For the
sake of the "simplest solution that could possibly work," I'd go with
Male/Female. No added complexity in having to format the data for the
view.
How many types? I only see two types, "forname", "middlename". Are you
trying to build a baby name to put into a "shopping cart" of some sort?
I'm trying to develop an app where the full proposed baby name is kind
of built up by the user - i envisage some dragging and dropping to
reorder the firstnames - several combinations of "(forname +
middle(optional)) + surname" can be reordered to generate the final full
name and yes, I can only think that forname and middle name will be
necessary. Such a seemingly simple task but when I get to think about it
the options for the model seem endless!
Also, I don't want to end up in ruby typing things like this.
name = Name.find_by_name("some_name") # seems ridiculous - too many
names.
The names would be generated by the user, they are proposed new baby
names. The surname of the baby is of course fixed but needs to be
entered, it is that of the parents. Hope that makes sense.
Amazing how much there is to think about from a seemingly trivial job!
The names would be generated by the user, they are proposed new baby
names. The surname of the baby is of course fixed but needs to be
entered, it is that of the parents. Hope that makes sense.
Amazing how much there is to think about from a seemingly trivial job!
Indeed, but I think you're overcomplicating the issue.
bb
So, a simple form with the following fields:
Forename, Surname (both stored as strings). *Two* check boxes to
determine whether the name is for a male and/or female, and of course a
save button.
Present this form only after a User has logged in.
Now, a ProposedNames table with the following columns:
This allows Users to save their proposed names into a database for later
retrieval.
You can then give the view permission to re-order and alter these names
at any time, by displaying a list of proposed names to the User in a
secure area.
No validation on the column names are necessary, realistically.
Unless I've misunderstood your request, I don't see any problems with
this approach.
An unlimited amount? In that case, you might consider storing the
entered forenames and middles names into separate tables and creating a
suggestion tool.
Well yes, I believe so. In the vast majority of cases people just have
firstname surname, also firstname middlename surname. But in essence
they could have 100 middle names; although it's a little unlikely I
don't believe there are legal constraints here in the UK.
Pragmatically though -
I think I'll go with a minor adaptation(s) of your first solution..
Really appreciate your other points re how I might handle the form and
logic. Got to love railscasts, I'd be nowhere without them, they are
truly excellent.
Well yes, I believe so. In the vast majority of cases people just have
firstname surname, also firstname middlename surname. But in essence
they could have 100 middle names; although it's a little unlikely I
don't believe there are legal constraints here in the UK.
Pragmatically though -
I think I'll go with a minor adaptation(s) of your first solution..
Really appreciate your other points re how I might handle the form and
logic. Got to love railscasts, I'd be nowhere without them, they are
truly excellent.
I agree with your proposed structure. It would be my recommendation, but
you did specify 'unlimited'.
It seems *pointless* for a human to have > 7 names.
Apologies for omitting the midname column from my original
recommendation.
Now if we could just stop thinking that the world is composed solely
of middle class white anglo saxon males and face the reality. Naming
conventions in some cultures go well beyond forename plus surname.
Those people also live in the UK.
I also note that you are omitting titles and suffixes such as "Queen
Elizabeth II" who is also called "Elizabeth Alexandra Mary Windsor".
Or even "Hank Williams Jr" or "Hank WIlliams III" or "Sir Robert
Geldof"
Some people have only one name which is neither a forename or a surname.
Lets ignore the artist formerly known a Prince for a moment
I also note that you are omitting titles and suffixes such as "Queen
Elizabeth II" who is also called "Elizabeth Alexandra Mary Windsor".
Or even "Hank Williams Jr" or "Hank WIlliams III" or "Sir Robert
Geldof"
Some people have only one name which is neither a forename or a surname.
Lets ignore the artist formerly known a Prince for a moment