我想使用本教程将AJAX搜索字段添加到我的应用程序:http://www.rymcmahon.com/articles/11
一切都运作良好,但搜索JS领域。它根本不起作用。终端控制台中的错误:
ActionView :: MissingTemplate(缺少模板产品/搜索结果,应用程序/搜索结果{:locale => [:en],:formats => [:js,:html],:variants => [],:handlers => [:raw,:erb,:html,:builder,:ruby,:jbuilder,:haml]
Chrome中的JS控制台
rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body = 1:189获取http://localhost:3000/products?utf8=%E2%9C%93&search=PKP&commit=search 500(内部服务器错误)
我有turbolinks v.5和rails 5.1.6。
根据'turbolinks','〜> 5'
宝石'jquery-rails'
宝石'轨道','〜> 5.1.6'
就像找不到这个文件:
/products/_search-results.就是.日本
$("#product_table").hide();
$("#search-results").html("<%= escape_javascript(render :partial =>'results') %>");
我应该为此添加一些路线吗?谢谢你的建议。
以防万一我会添加其他文件:
我的索引方法:
class ProductsController < ApplicationController
def index
if params[:search]
@search_results_products = Product.options_sortable(params)
respond_to do |format|
format.js {render "search-results"}
format.html
end
else
@products = Product.all.paginate(:page =>params[:page], :per_page => 20)
end
end.....
index.html.haml:
.container-fluid
%h2.center
=link_to "Create New Product", new_product_path
=render 'search_products'
%br
%h1.center List of all the Products
#product-table
=render 'table_products'
#search-results
.col-lg-2.offset-md-5
=will_paginate(@product)
我会把其他文件放在这里。
_table.products:
.col-md-8.offset-md-2
%table.frame
%thread
%tr.h2
%th
=link_to "Name", sort: "product_name"
%th
=link_to "Description", sort: "description"
%th Order Name
%th options
%tbody
[email protected] do |product|
%tr
%th.h4
=product.product_name
%th
=product.description
%th
=product.order.name
-if product.order.user == current_user
%th
=link_to 'edit', edit_product_path(product)
||
=link_to 'delete', product_path(product),
remote: true,
method: :delete,
data: { confirm: 'Are you sure?'}
-else
%th
no permission
_results.html.haml
.col-md-8.offset-md-2
%table.frame
%thread
%tr.h2
%th
=link_to "Name", sort: "product_name"
%th
=link_to "Description", sort: "description"
%th Order Name
%th options
%tbody
-@search_results_products.each do |product|
%tr
%th.h4
=product.product_name
%th
=product.description
%th
=product.order.name
-if product.order.user == current_user
%th
=link_to 'edit', edit_product_path(product)
||
=link_to 'delete', product_path(product),
remote: true,
method: :delete,
data: { confirm: 'Are you sure?'}
-else
%th
no permission
和_search_products.html.haml
.col-lg-4.offset-md-4
=form_tag(products_path, :method => "get", remote: true) do
.form-group.form-control-md
=text_field_tag :search, params[:search], placeholder: 'Enter search text'
=submit_tag 'search', class: "btn"