Custom field helper for person's height

Maybe somebody can point me in the right direction on this one. One
field in my model is a person’s height in inches. The form has the
following code to let the user enter his/her height:

<%= text_field ‘condition’, ‘height’ %> inches

I want to change this into two drop down lists. One for height in feet
and the other for height in inches. I would prefer two drop downlists
one for height in feet and the other for the inches. Something that I
could implement as:

<%= select_height ‘condition’, ‘height’ %>

I think I can figure out the HTML generation part, but what I’m
confused about is how to set it up where when the form is submitted
that the height field is automatically populated via the standard:

@condition =[:condition])

With two select lists, your HTML will look something like this:

4 ... 1 ...

One of the cool things you can do with ActiveRecord is map nonexistent
database columns with fields on a form. So even though “feet” and
“inches” are not part of your Condition model, you can still have a
form set them and do the logic through the model itself. For instance:

class Condition < ActiveRecord::Base

This is the key here, because this will

give you get/set methods for your “columns”

attr_accessor :feet
attr_accessor :inches

Now that you have your height in feet/inches,

you can set it by the @feet and @inches variables

you gained from attr_accessor()

def before_save
@height = @feet + @inches