how can I "DRYize" this method?

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 %>

Hi --

tnks guy! it works, I tried exactly this, but except the "form" var.

very tnks!