【发布时间】:2016-02-18 09:58:59
【问题描述】:
我有一个模型的 simple_form。新动作 si basic 的形式如下:
<%= simple_form_for @patient do |f| %>
.... fields
<% end %>
我想在New 视图中使用此表单,但也想在带有 AJAX 的引导模式中使用。如果我使用这种语法:
<%= render partial: 'patients/form', locals: {patient: @patient, remote: true} %>
但是当我这样做时,我只能使用远程访问本地变量,而不是 @remote,这将在 new 视图中呈现错误。
编辑
对局部的调用:
<%= render partial: 'patients/form', locals: {patient: @patient, remote: true } %>
还有形式:
<%= simple_form_for @patient, remote: @remote do |f| %>
.... fields
<% end %>
有什么方法可以做到这一点? 谢谢!
【问题讨论】:
-
为什么会导致错误?你得到什么错误?
-
在视图中,如果我使用@remote 变量设置表单
remote: @remote没有值,并且如果我使用remote: remote我在新视图中出现错误 -
只需给它起一个不同的名字......
remote_toggle: true然后在你的部分中调用data: { remote: remote_toggle } -
是不是因为你没有从新的远程传递远程本地变量是未定义的?
-
看起来像这样。我一会儿试试。
标签: ruby-on-rails ajax