Passing ActionView::Helpers::FormBuilder to a partial

拟墨画扇 提交于 2019-11-30 20:21:40

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!