Ruby on rails 远程和远程的url\u:true

Ruby on rails 远程和远程的url\u:true,ruby-on-rails,ruby,ajax,forms,Ruby On Rails,Ruby,Ajax,Forms,我对Rails有一个问题。我想要一个选择表单,它在单击时呈现局部视图。我希望局部视图在不刷新整个文档(Ajax)的情况下有效,但似乎remote:true对我不起作用 我当前拥有的内容并刷新整个文档: =form_tag url_for(action::index),方法:“get”do //在html字段中存储一些信息以供进一步使用 -shops_array=@shops.collect.with_index{shop,i{shop.title,shop.id,{'address'=>[sho

我对Rails有一个问题。我想要一个选择表单,它在单击时呈现局部视图。我希望局部视图在不刷新整个文档(Ajax)的情况下有效,但似乎
remote:true
对我不起作用

我当前拥有的内容并刷新整个文档:

=form_tag url_for(action::index),方法:“get”do
//在html字段中存储一些信息以供进一步使用
-shops_array=@shops.collect.with_index{shop,i{shop.title,shop.id,{'address'=>[shop.address,shop.zipcode,shop.city]。加入(“”},{'id'=>'shop'+String(i)}
=选择标签:shop\u id,选择选项(shops\u数组,@shop\u id),提示:“您的店铺:”,数据:{submit\u on\u change:true}
我所尝试的:

=form_tag url_for(action::index),remote:true,方法:“get”do
//在html字段中存储一些信息以供进一步使用
-shops_array=@shops.collect.with_index{shop,i{shop.title,shop.id,{'address'=>[shop.address,shop.zipcode,shop.city]。加入(“”},{'id'=>'shop'+String(i)}
=选择标签:shop\u id,选择选项(shops\u数组,@shop\u id),提示:“您的店铺:”,数据:{submit\u on\u change:true}
如何将
remote:true
选项与
url\u一起应用于
?如果不可能,我可以使用一些帮助来找到解决方法。

根据,您可以为
表单标签
方法指定
远程
选项,如下所示:

form_tag(url_for(controller: :charmander, action: :ember), remote: true, method: :get, class: 'pokemon-form') do
  # form logic
end
$('.pokemon-form').on('ajax:success', function (event, data, status, xhr) {
  // Do something with data, which would be the rendered partial returned
  // from the server call.
});
但是,当提交整个表单时,这只会触发
ajax:success
事件

根据您的问题,在我看来,当选择值更改时,您希望重新渲染某些部分。我不确定如何使用
submit\u on\u change
数据属性,但是如果我正确地假设您在选择变量更改时提交整个表单,那么您所需要做的就是监听整个表单的
ajax:success
事件,如下所示:

form_tag(url_for(controller: :charmander, action: :ember), remote: true, method: :get, class: 'pokemon-form') do
  # form logic
end
$('.pokemon-form').on('ajax:success', function (event, data, status, xhr) {
  // Do something with data, which would be the rendered partial returned
  // from the server call.
});

最后使用了onclick和JavaScript函数。虽然这可能不是最好的解决方案,也不是更漂亮的,但它对我来说就像一个魅力

= select_tag :shop_id, options_for_select(shops_array, @shop_id), prompt: "Your shop :", onclick: 'ajaxSelectedShop('+String(8)+')'