Ruby on rails 对AJAX和非AJAX调用使用相同的rails表单

Ruby on rails 对AJAX和非AJAX调用使用相同的rails表单,ruby-on-rails,ajax,Ruby On Rails,Ajax,我有一个模型的简单表格。新动作的形式是基本的,如下所示: <%= simple_form_for @patient do |f| %> .... fields <% end %> 但是当我这样做时,我只能用remote访问局部变量,而不是@remote,这将在new视图中呈现错误 编辑 要求部分赔偿的呼吁: <%= render partial: 'patients/form', locals: {patient: @patient, remote: tr

我有一个模型的简单表格。新动作的形式是基本的,如下所示:

<%= simple_form_for @patient do |f| %>
    .... fields
<% end %>
但是当我这样做时,我只能用remote访问局部变量,而不是@remote,这将在
new
视图中呈现错误

编辑

要求部分赔偿的呼吁:

<%= render partial: 'patients/form', locals: {patient: @patient, remote: true } %>

及表格:

<%= simple_form_for @patient, remote: @remote do |f| %>
    .... fields
<% end %>

.... 领域
有没有办法做到这一点? 谢谢

您可以将
请求
作为
Ajax
发送到model,并使用
表单
使用
remote:request.xhr?
,这样您就可以将表单用于Ajax和非Ajax调用

在形式上

#form

<%= simple_form_for @patient, remote: request.xhr? do |f| %>
    .... fields
<% end %>
<% modal ||= false %>
<% remote = modal ? true : false %>
<%= simple_form_for @patient, remote: remote do |f| %>
    .... fields
<% end %>
在形式上

#form

<%= simple_form_for @patient, remote: request.xhr? do |f| %>
    .... fields
<% end %>
<% modal ||= false %>
<% remote = modal ? true : false %>
<%= simple_form_for @patient, remote: remote do |f| %>
    .... fields
<% end %>

.... 领域

为什么会导致错误?你得到了什么错误?在视图中,如果我使用@remote变量设置表单
remote:@remote
没有值,如果我使用
remote:remote
我在新视图中得到一个错误,只需将其称为另一个名称
remote\u toggle:true
然后调用
data:{remote:remote\u toggle}
在您的部分中,因为您没有从新的远程本地变量传递remote,所以未定义?看起来是这样的。我马上就去试试,它坏了。在表单上,
request.xhr?
是空的。@hmail您是否将链接更改为我的链接?是的,我将远程数据放在了链接中。@hmail您可以发布您单击链接时生成的日志吗?上面写着:
Started GET”/appointment/new?clinic_id=2&medical_id=17”对于2016-02-18 13:39:28+0200时的127.0.0.1,任命控制员处理#新为JS