Hi all, well I have this helper in my form, but it isn''t DRY, as you see: <%= f.text_field(:birth_date, :size => ''10'', :maxlength => ''10'', :class => "format-d-m-y divider-slash split-date", :value => (@person.birth_date.nil? ? '''': @person.birth_date)) %> so, @person and :birth_date must be dymamic in a helper. How can I write those on a helper? --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Wed, Jan 21, 2009 at 4:39 PM, flaubert <aflauberts-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > > well I have this helper in my form, but it isn''t DRY, as you see: > > <%= f.text_field(:birth_date, :size => ''10'', :maxlength => > ''10'', :class => "format-d-m-y divider-slash split-date", :value => > (@person.birth_date.nil? ? '''': @person.birth_date)) %> > > so, @person and :birth_date must be dymamic in a helper. > > > How can I write those on a helper? > > >helper: def date_field(form, method, model) form.text_field(method, :size => 10, :maxlength => 10, :class => ''format-d-m-y divider-slash split-date'', :value => (model.send(method).nil? ? '''' : model.send(method)) ) end view: <%= date_field(f, :birth_date, @person) %> You could also create a custom form builder and add a date_field method there to get the following in your view: <%= f.date_field :birth_date %> -- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Wed, 21 Jan 2009, flaubert wrote:> > Hi all, > > > well I have this helper in my form, but it isn''t DRY, as you see: > > <%= f.text_field(:birth_date, :size => ''10'', :maxlength => > ''10'', :class => "format-d-m-y divider-slash split-date", :value => > (@person.birth_date.nil? ? '''': @person.birth_date)) %> > > so, @person and :birth_date must be dymamic in a helper.What does your form_for line look like? If you''ve got: form_for :person ... do |f| f.text_field(:birth_date) (or some small variations on that) you''ll get @person.birth_date in the field automatically. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) http://www.wishsight.com => Independent, social wishlist management! --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
tnks guy! it works, I tried exactly this, but except the "form" var. very tnks! On 21 jan, 11:49, Andrew Timberlake <and...-642hCh26+Dt3UeSHeRwt+FaTQe2KTcn/@public.gmane.org> wrote:> On Wed, Jan 21, 2009 at 4:39 PM, flaubert <aflaube...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi all, > > > well I have this helper in my form, but it isn''t DRY, as you see: > > > <%= f.text_field(:birth_date, :size => ''10'', :maxlength => > > ''10'', :class => "format-d-m-y divider-slash split-date", :value => > > (@person.birth_date.nil? ? '''': @person.birth_date)) %> > > > so, @person and :birth_date must be dymamic in a helper. > > > How can I write those on a helper? > > helper: > def date_field(form, method, model) > form.text_field(method, > :size => 10, > :maxlength => 10, > :class => ''format-d-m-y divider-slash split-date'', > :value => (model.send(method).nil? ? '''' : > model.send(method)) > ) > end > > view: > <%= date_field(f, :birth_date, @person) %> > > You could also create a custom form builder and add a date_field method > there to get the following in your view: > <%= f.date_field :birth_date %> > > -- > Andrew Timberlakehttp://ramblingsonrails.comhttp://www.linkedin.com/in/andrewtimberlake > > "I have never let my schooling interfere with my education" - Mark Twain--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---