Reputation: 1745
Is there a way I can turn this:
<%= f.datetime_select :truckleft, :start_year => Date.current.year, :end_year => Date.current.year, :include_blank => true %>
into a helper, because I need to use it a lot throughout the form
I do however would like the rest to stay in the view file, like the:
<%= form_for(@trip) do |f| %>
so far nothing worked yet
Thank you so much!
ps, i'm using Rails 3..
Upvotes: 1
Views: 804
Reputation: 1745
got it after changing neutrino's awesome answer a little bit:
in the helper:
def truck_selector(f, field)
f.datetime_select field, :start_year => Date.current.year, :end_year => Date.current.year, :include_blank => true
end
in the view:
<%= truck_selector(f, :truckleft) %>
<%= truck_selector(f, :truckarrive) %>
Upvotes: 1
Reputation: 24164
Have you tried something like this:
def truck_left_selector(f)
f.datetime_select :truckleft, :start_year => Date.current.year, :end_year => Date.current.year, :include_blank => true
end
Then in your view,
<%= form_for(@trip) do |f| %>
...
<%= truck_left_selector(f) %>
...
<% end %>
Upvotes: 1