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</p> 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.new(params[:condition]) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
atraver-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Aug-29 16:26 UTC
Re: Custom field helper for person''s height
With two select lists, your HTML will look something like this: <select name="condition[feet]"> <option value="4">4</option> ... </select> <select name="condition[inches]"> <option value="1">1</option> ... </select> 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 end end --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---