Railsアプリにアルゴリア検索を使用しています。 typehead.jsを使用して自動補完メソッドを立ち上げました。しかし、URLに大文字があると正しくリダイレクトできません...これが私のコードです:
// replace YourIndexName by the name of the index you want to query.
var index = algolia.initIndex('Pin');
// Mustache templating by Hogan.js (http://mustache.github.io/)
var template = Hogan.compile('<div class="hit">' +
'<a href="http://yhumans.com/{{{twitter}}}">'
+
'<div class="small-text">' +
'{{{ _highlightResult.name.value }}} ' +
'</div>' +
'<div class="small-text">' +
'@' +
'{{{ _highlightResult.twitter.value }}} ' +
'</div>' +
'</a>' +
'</div>');
// typeahead.js initialization
$('#user-search').typeahead(null, {
source: index.ttAdapter({ hitsPerPage: 5 }),
displayKey: 'twitter',
templates: {
suggestion: function(hit) {
// select matching attributes only
hit.matchingAttributes = [];
for (var attribute in hit._highlightResult) {
if (attribute === 'name' || attribute == 'twitter') {
// already handled by the template
continue;
}
// all others attributes that are matching should be added in the matchingAttributes array
// so we can display them in the dropdown menu. Non-matching attributes are skipped.
if (hit._highlightResult[attribute].matchLevel !== 'none') {
hit.matchingAttributes.push({ attribute: attribute, value: hit._highlightResult[attribute].value });
}
}
// render the hit using Hogan.js
return template.render(hit);
}
}
});
問題は、ユーザーが結果をクリックしてページにアクセスできるようにするために使用している次の行にあります。
<a href="http://yhumans.com/{{{twitter}}}">'
実際、一部のユーザーは Twitter のユーザー名に大文字を使用しているため、検索結果のプロファイルに適切にリダイレクトできません。
説明させてください: http://yhumans.com/mynameは正しい URL です。http://yhumans.com/MyNameは間違った URL です。変数 "twitter" に小文字を使用しようとしました。しかし、私はそれを適切に行う方法を見つけることができませんでした。
それを行う 1 つの方法は、twitter 変数を小文字にすることです。しかし問題は、関数が 'downcase!' であることです。jsでは動かないようです。
何か案は ?