你好,我是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
search.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>
app.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
答案 0 :(得分:0)
以下资源:
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>