Ruby on rails usj/ajax远程调用不起作用,页面转到目标url,而不是停留在同一页面中

Ruby on rails usj/ajax远程调用不起作用,页面转到目标url,而不是停留在同一页面中,ruby-on-rails,ujs,Ruby On Rails,Ujs,单击远程链接后,我的体验是 将更新部分内容,浏览器应保持在同一页面中 但是当前的行为是浏览器指向远程链接url,并给出错误信息 错误ActionController::ProductsController#filter_产品中的未知信息 汉密尔顿指数 routes.rb 控制器 application.js 您将路由中的链接设置为具有GET方法,但在链接中,您将其覆盖为POST: …,方法::post,… 因此,它会将此路由视为一种post方法,而您没有这种方法。您的链接应该是: = link_

单击远程链接后,我的体验是

将更新部分内容,浏览器应保持在同一页面中

但是当前的行为是浏览器指向远程链接url,并给出错误信息

错误
ActionController::ProductsController#filter_产品中的未知信息

汉密尔顿指数 routes.rb 控制器 application.js
您将路由中的链接设置为具有
GET
方法,但在链接中,您将其覆盖为
POST

…,方法::post,…

因此,它会将此路由视为一种post方法,而您没有这种方法。您的链接应该是:

= link_to cate.name , filter_products_path(cate.id) , remote: true, id: cate.id

如果没有
method
,它将默认为
GET

filter\u products是一种GET或post方法?我想我在routeOff主题中将其定义为
GET
方法:你接受过正确的答案吗?或者你只是路过问下一个问题?
get 'products/filter_products/:category' => 'products#filter_products', as: :filter_products
  def filter_products
    @products = ProductCategory.where("id = ?",params["category"].to_i).first.products
    respond_to do |format|
      format.js
   end
  end
//= require jquery
//= require jquery_ujs
//= require_tree .
= link_to cate.name , filter_products_path(cate.id) , remote: true, id: cate.id