I was following Railscasts 196 and 197 in order to better learn dynamic nested model forms and I can across this problem.
I am not sure how to pass javascript through the link_to_function, the class of a field contains a jquery timepicker.
def link_to_add_fields(name, f, association)
new_object = f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
render(association.to_s.singularize + "_fields", :f => builder)
end
link_to_function(name, "add_fields(this, '#{association}', ' #{escape_javascript(fields)}')")
end
I have tried using html_safe, raw and f around the fields variable, and none have been working.
The html output of an added form using escape_javascript looks like this:
Start Time<input class="time" ...
Using raw and html_safe instead of escape_javascript produces this:
Start Time<input class="time" ...
What I would like is this:
Start Time<input class="time hasDatepicker" ...
hasDatePicker being the jquery function for the class time. It is probably something simple that I havent realized yet. But, thank you for reading and your comments ahead of time.
If you feel anymore code is required just tell me. I figure this is all that is required. I am using Rails 3.1 and Ruby 1.9.2p290.
Thanks Again.