I''m trying to figure out the rails why to break a single database field out into multiple fields on a form, very similar to how rails does with dates. How can I create my own object that mirrors the date objects behaviur in how it accepts the multiparameter assignment from the form. Example: A phone number field (to force formating on the user) could be broken into 3 form fields, formated server side, and written to the database in a single field. -- Posted via http://www.ruby-forum.com/.
On Mon, 2006-01-30 at 17:54 +0100, Fred Wittekind wrote:> I''m trying to figure out the rails why to break a single database field > out into multiple fields on a form, very similar to how rails does with > dates. How can I create my own object that mirrors the date objects > behaviur in how it accepts the multiparameter assignment from the form. > > Example: > A phone number field (to force formating on the user) could be broken > into 3 form fields, formated server side, and written to the database in > a single field.---- there are helpers for phone numbers... <%= number_to_phone(212-555-1212) %> 212-555-1212 there are validation methods such as validates_format_of attr, :with => regexp (pages 266 - 274 of Agile book) there is also a section on ''aggregation'' in Agile book that discusses handling/joining/separating strings (pages 257 - 263) Craig
Craig White wrote:> On Mon, 2006-01-30 at 17:54 +0100, Fred Wittekind wrote: >> I''m trying to figure out the rails why to break a single database field >> out into multiple fields on a form, very similar to how rails does with >> dates. How can I create my own object that mirrors the date objects >> behaviur in how it accepts the multiparameter assignment from the form. >> >> Example: >> A phone number field (to force formating on the user) could be broken >> into 3 form fields, formated server side, and written to the database in >> a single field. > ---- > there are helpers for phone numbers... > <%= number_to_phone(212-555-1212) %> > 212-555-1212For what I''m trying to do, I need a form phone number helper, that displays 3 text enty fields. I think I can write this helper though, if I can figure out the rest of this.> there are validation methods such as validates_format_of attr, :with => > regexp (pages 266 - 274 of Agile book)I''m sure I will have to address validation, but not ready for that yet.> there is also a section on ''aggregation'' in Agile book that discusses > handling/joining/separating strings (pages 257 - 263)I''ve looked at the section on aggregation, and tried very unsuccessfully at doing this with a composed_of aggregation. I got as far as the form helper working, but as soon as I hit submit, it got a multiparameter assignment error. It looked like ActiveRecord couldn''t figure out where the object used in the aggregation was defined.> Craig-- Posted via http://www.ruby-forum.com/.
Fred Wittekind wrote:> Craig White wrote: > >>On Mon, 2006-01-30 at 17:54 +0100, Fred Wittekind wrote: >> >>>I''m trying to figure out the rails why to break a single database field >>>out into multiple fields on a form, very similar to how rails does with >>>dates. How can I create my own object that mirrors the date objects >>>behaviur in how it accepts the multiparameter assignment from the form. >>> >>>Example: >>>A phone number field (to force formating on the user) could be broken >>>into 3 form fields, formated server side, and written to the database in >>>a single field. >> >>---- >>there are helpers for phone numbers... >><%= number_to_phone(212-555-1212) %> >>212-555-1212 > > > For what I''m trying to do, I need a form phone number helper, that > displays 3 text enty fields. I think I can write this helper though, if > I can figure out the rest of this. > > >>there are validation methods such as validates_format_of attr, :with => >>regexp (pages 266 - 274 of Agile book) > > > I''m sure I will have to address validation, but not ready for that yet. > > >>there is also a section on ''aggregation'' in Agile book that discusses >>handling/joining/separating strings (pages 257 - 263) > > > I''ve looked at the section on aggregation, and tried very unsuccessfully > at doing this with a composed_of aggregation. I got as far as the form > helper working, but as soon as I hit submit, it got a multiparameter > assignment error. It looked like ActiveRecord couldn''t figure out where > the object used in the aggregation was defined. > > >>Craig > > >I think aggregation is more about having *multiple* database columns that you want to group into a child object for convenience sake... not taking a single column and presenting it as multiple input boxes on a form. Sounds like a helper to me. b
Ben Munat wrote:> I think aggregation is more about having *multiple* database columns > that you want to > group into a child object for convenience sake... not taking a single > column and > presenting it as multiple input boxes on a form. Sounds like a helper to > me.Yeah, the aggregation didn''t work very well. I know I need the helper portion of this, and I even think I know how to do that part. The part I can''t figure out, is how to handle it properly in the model, to put it back together into a single field to write back to the database. -- Posted via http://www.ruby-forum.com/.