Bojan Mihelac
2006-Jun-02 21:01 UTC
[Rails] Advice, why value_before_type_cast in FormHelper?
I am wondering why is in creating text fields with form_helper used value_before_type_cast instead of attribute value for field value? I set rails enviroment so date fields are in european format (dd.mm.yyyy) and would like to have same format in forms, but because of value_before_type_cast is called, form fields are filled with ''yyyy-mm-dd'' or timestamp integer, etc. Thoughts / comments / sugestions? thanks in advance, -- Bojan Mihelac Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com -> tools, scripts, tricks from our code lab: http://source.mihelac.org
Bojan Mihelac
2006-Jun-03 07:49 UTC
[Rails] Advice, why value_before_type_cast in FormHelper?
Bojan Mihelac wrote:> I am wondering why is in creating text fields with form_helper used > value_before_type_cast instead of attribute value for field value? > > I set rails enviroment so date fields are in european format > (dd.mm.yyyy) and would like to have same format in forms, but because of > value_before_type_cast is called, form fields are filled with > ''yyyy-mm-dd'' or timestamp integer, etc. > > Thoughts / comments / sugestions? > thanks in advance, >or is there any tutorial how to override fields produced with FormHelper? thanks, Bojan -- Bojan Mihelac Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com -> tools, scripts, tricks from our code lab: http://source.mihelac.org
Brian Hogan
2006-Jun-04 07:10 UTC
[Rails] Advice, why value_before_type_cast in FormHelper?
I''ve asked this many times before and have never gotten an answer. However, form fields will look at the attribute on the model if it''s not in the database. Here''s a simplified (non-working) example to modify the formatting of the created_at field class YourModel < ActiveRecord::base def formatted_date=(date) self.created_at = date end def formatted_date # apply your special formatting here end end Then, in your form, just do <%= text_field "your_model", "formatted_date" %> That''s how I manage to do the special formatting that I need and still make use of the helpers. I did write a plugin that allowed you to pass a formatted string into the text_field helper, but I threw it away because it was too difficult to make it work for select tags, options_for_select, and others. I found the above approach to be a decent solution. If anyone from the core can comment on this, that would be great. Hope that helps you out. On 6/3/06, Bojan Mihelac <lists@mihelac.org> wrote:> Bojan Mihelac wrote: > > I am wondering why is in creating text fields with form_helper used > > value_before_type_cast instead of attribute value for field value? > > > > I set rails enviroment so date fields are in european format > > (dd.mm.yyyy) and would like to have same format in forms, but because of > > value_before_type_cast is called, form fields are filled with > > ''yyyy-mm-dd'' or timestamp integer, etc. > > > > Thoughts / comments / sugestions? > > thanks in advance, > > > > or is there any tutorial how to override fields produced with FormHelper? > > thanks, > Bojan > > -- > Bojan Mihelac > Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com > -> tools, scripts, tricks from our code lab: http://source.mihelac.org > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Bojan Mihelac
2006-Jun-05 08:04 UTC
[Rails] Advice, why value_before_type_cast in FormHelper?
Thanks Brian, in the middtime I succeed to create custom date select field that works with custom date format (dd.mm.yyyy). There were few new problems I run into while solving these so I would post all the code and explanation on my site asap. best regards, Bojan Brian Hogan wrote:> I''ve asked this many times before and have never gotten an answer. > > However, form fields will look at the attribute on the model if it''s > not in the database. > > Here''s a simplified (non-working) example to modify the formatting of > the created_at field > > class YourModel < ActiveRecord::base > > def formatted_date=(date) > self.created_at = date > end > > def formatted_date > # apply your special formatting here > end > > > end > > Then, in your form, just do > > <%= text_field "your_model", "formatted_date" %> > > That''s how I manage to do the special formatting that I need and still > make use of the helpers. I did write a plugin that allowed you to pass > a formatted string into the text_field helper, but I threw it away > because it was too difficult to make it work for select tags, > options_for_select, and others. I found the above approach to be a > decent solution. > > If anyone from the core can comment on this, that would be great. > > Hope that helps you out. > > > On 6/3/06, Bojan Mihelac <lists@mihelac.org> wrote: >> Bojan Mihelac wrote: >> > I am wondering why is in creating text fields with form_helper used >> > value_before_type_cast instead of attribute value for field value? >> > >> > I set rails enviroment so date fields are in european format >> > (dd.mm.yyyy) and would like to have same format in forms, but >> because of >> > value_before_type_cast is called, form fields are filled with >> > ''yyyy-mm-dd'' or timestamp integer, etc. >> > >> > Thoughts / comments / sugestions? >> > thanks in advance, >> > >> >> or is there any tutorial how to override fields produced with FormHelper? >> >> thanks, >> Bojan >> >> -- >> Bojan Mihelac >> Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com >> -> tools, scripts, tricks from our code lab: http://source.mihelac.org >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Bojan Mihelac Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com -> tools, scripts, tricks from our code lab: http://source.mihelac.org