gpt4 book ai didi

javascript - Algolia Instantsearch for rails 没有结果

转载 作者:行者123 更新时间:2023-11-28 02:19:19 26 4
gpt4 key购买 nike

大家好,我是 Ror 和 Js 的新手,我想在我的应用程序上安装 algolia Instantsearch,我的产品出现在 algolia 索引中,但我无法在我的 html 页面(产品索引)上成功显示我的 Instantsearch 和结果如果有人可以帮助我,那就太好了:-)提前致谢

这是我的代码:

我包括的布局:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.3/dist/instantsearch.min.css">

product.rb(模型):

include AlgoliaSearch
algoliasearch if: :active? do
attribute :name, :brand, :category, :color, :size, :price
end

搜索.html.erb:

    <div>
<input id="search-input" placeholder="Search for products">
<!-- We use a specific placeholder in the input to guides users in their search. -->
</div>
</header>
<main>
<div id="hits"></div>
<div id="pagination"></div>
</main>

<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@2.3/dist/instantsearch.min.js"></script>
<script src="app.js"></script>


<script type="text/html" id="hit-template">
<div class="hit">
<div class="hit-image">
<img src="{{image}}" alt="{{name}}">
</div>
<div class="hit-content">
<h3 class="hit-price">${{price}}</h3>
<h2 class="hit-name">{{{_highlightResult.name.value}}}</h2>
<p class="hit-description">{{{_highlightResult.description.value}}}</p>
</div>
</div>
</script>

应用程序.js:

var search = instantsearch({
// Replace with your own values
appId: "012967GRTQ",
apiKey: "a3f100606d982f64d7c25410c672f5f5", // search only API key, no ADMIN key
indexName: 'Product',
urlSync: true,
searchParameters: {
hitsPerPage: 10
}
});

search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-input'
})
);

search.addWidget(
instantsearch.widgets.hits({
container: '#hits',
templates: {
item: document.getElementById('hit-template').innerHTML,
empty: "We didn't find any results for the search <em>\"{{query}}\"</em>"
}
})
);

search.addWidget(
instantsearch.widgets.pagination({
container: '#pagination'
})
);

search.start();

配置/初始化程序/algoliasearch.rb

require 'rubygems'
require 'algoliasearch'

Algolia.init application_id: "XXXXXX",
api_key: "xxxxxxxxxxxx"
index = Algolia::Index.new("Product")

我从以下位置导入了 css:.....github.com/algolia/examples/blob/master/instant-search/instantsearch.js/assets/style.css.....

最佳答案

以下资源:

GET http://localhost:3000/app.js 404 (Not Found)
GET http://localhost:3000/js/main.js 404 (Not Found)

这是我的布局:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>XXXXXXX</title>
<%= csrf_meta_tags %>
<%= action_cable_meta_tag %>
<%= javascript_include_tag "https://js.stripe.com/v2/" %>
<%= stylesheet_link_tag 'application', media: 'all' %>

<link rel="stylesheet" type="text/css" href="css/jTinder.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.js@2.3/dist/instantsearch.min.css">

<%= favicon_link_tag 'favicon.ico'%>
</head>

<body>
<%= render 'shared/navbar' %>
<%= render 'shared/message' %>
<%= yield %>
<%= javascript_include_tag "https://maps.google.com/maps/api/js?libraries=places&key=#{ENV['GOOGLE_API_BROWSER_KEY']}" %>
<%= javascript_include_tag "https://cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/markerclusterer/src/markerclusterer_compiled.js" %>
<%= javascript_include_tag "https://cdn.rawgit.com/printercu/google-maps-utility-library-v3-read-only/master/infobox/src/infobox_packed.js" %>
<%= javascript_include_tag 'application' %>
<script type="text/javascript" src="autocomplete.js"></script>


<script type="text/javascript" src="js/jquery.min.js"></script>
<!-- transform2d lib -->
<script type="text/javascript" src="js/jquery.transform2d.js"></script>
<!-- jTinder lib -->
<script type="text/javascript" src="js/jquery.jTinder.js"></script>
<!-- jTinder initialization script -->
<script type="text/javascript" src="js/main.js"></script>



<%= yield(:after_js) %>
<%= render 'pages/footer' %>

</body>
</html>

关于javascript - Algolia Instantsearch for rails 没有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48306570/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com