通过表单生成器在remote_function在轨?生成器、表单、remote_function

2023-09-10 17:33:15 作者:賣囡孩旳小火柴╯

我有选择对话框,在其中的变化,我需要抓住的价值,并通过远程功能得到分贝一些字段名称,然后再生成这些场下的形式,从选择框depwning上whatoption选择。

i have select box where on change i need to grab the value and via remote function get some field names from db and then generate those field further down the form depwning on whatoption from the select box is chosen.

现在的问题是在于字段中f.form_for所以使用formbuilder˚F有在选择框。因此,当我渲染部分通过ajax控制器我得到一个错误,因为我没有一个参考到当地的表单生成器F。

The problem is is that the fields are in a f.form_for so are using the formbuilder f that has the select box in. So when i render the partial via ajax in the controller i get an error as i dont have a reference to the local form builder f.

没有人知道如何或者如果我能得到引用表单生成器切开复位内固定可以通过它在远程函数调用,然后传递到我的当地人在部分?

does anyone know how or if i can get reference to the form builder orif can pass it in a remote function call and then pass into my locals in the partial ?

非常感谢,任何帮助将是伟大的,因为一直停留在这个很长的时间!

thanks alot, any help will be great as been stuck on this a long time!

欢呼 里克

推荐答案

我有同样的问题,我的解决方案是创建另一种形式建造者为同一对象,并把它传递给谐音。

I had the same problem and my solution was to create another form builder for the same object and to pass it on to the partials.

remote_action.js.erb:

'<%= form_for(@object) do |ff| /%> '
   $('#some_div').html("<%= j render(partial: 'some_partial', locals: {f: ff} %>"
'<% end %>' 

有重要的的form_for标签具有单引号或其他有javascript_escape问题

It is important that the form_for tag has single quotes or else there are javascript_escape problems.