点击远程链接后
部分将会更新,浏览器应保留在同一页面中。
但当前行为是浏览器前往远程链接网址,并给我错误
错误ActionController::UnknownFormat in ProductsController#filter_products
= link_to cate.name , filter_products_path(cate.id) , remote: true, method: :post, id: cate.id
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 .
答案 0 :(得分:0)
您可以在路线中设置指向GET
方法的链接,但在链接中,您可以将其覆盖为POST
,其中包含:
..., method: :post, ...
所以它将查找此路由作为您没有的post方法。您的链接应该是:
= link_to cate.name , filter_products_path(cate.id) , remote: true, id: cate.id
没有method
,默认情况下会为GET
。