Ruby on rails 表单_正在执行操作,但未正确呈现页面

Ruby on rails 表单_正在执行操作,但未正确呈现页面,ruby-on-rails,Ruby On Rails,我正在开发一个简单的搜索功能,它位于用户仪表板视图中,该视图也有自己的仪表板控制器。现在,搜索功能在单个模型上运行,执行操作后,它应该转到该特定模型的索引页。但是,索引页在搜索后不会被呈现,它仍保留在仪表板页中,即使日志显示它重定向到索引页 以下是日志: Started GET "/detected_vehicles?utf8=%E2%9C%93&%3Aq%5Blocation_eq%5D=1&commit=Search" for 127.0.0.1 at 2019-05-02

我正在开发一个简单的搜索功能,它位于用户仪表板视图中,该视图也有自己的仪表板控制器。现在,搜索功能在单个模型上运行,执行操作后,它应该转到该特定模型的索引页。但是,索引页在搜索后不会被呈现,它仍保留在仪表板页中,即使日志显示它重定向到索引页

以下是日志:

Started GET "/detected_vehicles?utf8=%E2%9C%93&%3Aq%5Blocation_eq%5D=1&commit=Search" for 127.0.0.1 at 2019-05-02 10:33:08 +0800
Processing by DetectedVehiclesController#index as JS
  Parameters: {"utf8"=>"✓", ":q"=>{"location_eq"=>"1"}, "commit"=>"Search"}
  Rendering detected_vehicles/index.html.slim within layouts/application
  Rendered shared/_flash.html.slim (3.1ms)
  Rendered detected_vehicles/index.html.slim within layouts/application (80.9ms)
  Rendered layouts/_navbar.html.slim (2.9ms)
  Rendered layouts/_footer.html.slim (3.6ms)
Completed 200 OK in 326ms (Views: 271.7ms | ActiveRecord: 6.4ms)
这是我的表格和代码:

我试着用form_标签来做同样的事情,结果正如预期的那样。以下是我使用form_标签的代码:


虽然我知道我现在可以解决form_tag解决方案,但我想找出我构建form_的方式有什么问题,因为它可能很快成为编写表单的标准,因为form_tag和form_for在技术上是不受欢迎的,正如我所读到的。

如果你仔细看,使用表单_时,您正在使用JS进行请求:

检测到的车辆控制器索引作为JS进行处理 因为表单_的集合为local:false:

:local-默认情况下,表单提交是远程且不引人注目的XHR。使用local:true禁用远程提交


因此,将local:true添加到form_with,看看会发生什么。

如果仔细观察,在使用form_with时,您使用的是JS请求:

检测到的车辆控制器索引作为JS进行处理 因为表单_的集合为local:false:

:local-默认情况下,表单提交是远程且不引人注目的XHR。使用local:true禁用远程提交


因此,添加local:true以形成_,并查看结果。

您使用turbolinks gem吗?是的,我使用turbolinks@Subash与您共享turbolinks gem吗?是的,我使用turbolinks@Subash
    = form_with url: detected_vehicles_path, method: :get, class: 'ui form' do |f|
        .field
            = select_tag(":q[location_eq]", options_from_collection_for_select(Camera.all, "id", "full_location"), class: 'form-control', id: 'detected_vehicle')
        = f.submit 'Search', class: 'form-control'
    = form_tag detected_vehicles_path, method: :get, class: 'ui form' do
        .field
            = select_tag(":q[location_eq]", options_from_collection_for_select(Camera.all, "id", "full_location"), class: 'form-control', id: 'detected_vehicle')
        = submit_tag 'Search', class: 'form-control'