Skip to content

Instantly share code, notes, and snippets.

@prathe
Created February 10, 2012 21:23
Show Gist options
  • Save prathe/1792984 to your computer and use it in GitHub Desktop.
Save prathe/1792984 to your computer and use it in GitHub Desktop.
<%= form_for @timesheet, :builder => TimesheetFormBuilder do |timesheet_form| %>
<%= timesheet_form.fields_for :worklogs do |worklog_form| %>
<%= worklog_form.text_field :monday %>
<% end %>
<% end %>
class TimesheetFormBuilder < ActionView::Helpers::FormBuilder
def text_field(method, opts)
#Get a reference to the model object
object = @template.instance_variable_get("@#{@object_name}")
value = object.send(method)
(opts ||= {}).merge!(value: value + 'h')
super(method, opts)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment