I am atempting to dinamically create form elements given a certain AJAX request.
This is my setup:
View:
<%= link_to \'Next\', check_
In the view, I've found that 'view_context' does not work in Rails 3.1. Instead try 'self' when creating a FormBuilder object.
s = ActionView::Helpers::FormBuilder.new(:student, @student, self, {}, proc{})
For anyone needing to build a form builder in the controller, view_context still works there. Using Rails 4.1.4:
@object = Object.new
@f = ActionView::Helpers::FormBuilder.new(:object, @object, view_context, {})
Try this in a console :
s = ActionView::Helpers::FormBuilder.new(:student, @student, @template, {}, proc{})
s.text_field :first_name
You will have the same error. I think the problem come from your creation of the form_builder object, even if I don't know the exact mistake...
Your solution seems to me to be a little much complex. You can try this solution :
#html.erb
<% form_for @student do |f| %>
<div id='guardian_student_details' class='hide-this-block'>
<%= render :partial => "student_details", :locals => { :s => f }) %>
</div>
<% end %>
#js
jQuery("#guardian_student_details").show();
Generally, I prefer keep javascript and ruby separated.