#soulmate{background-color:#fafafa;border:1pxsolid#bbb;display:none;font:12px/14px"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:normal;list-style:none;margin:00010px;padding:0;position:absolute;text-shadow:000white;/* play around with the top and left properties for correct positioning */top:201px;left:460px;width:579px;z-index:1000;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;-o-border-radius:4px;-khtml-border-radius:4px;border-radius:4px;-webkit-box-shadow:04px10pxrgba(0,0,0,0.2);-moz-box-shadow:04px10pxrgba(0,0,0,0.2);-khtml-box-shadow:04px10pxrgba(0,0,0,0.2);-ms-box-shadow:04px10pxrgba(0,0,0,0.2);-o-box-shadow:04px10pxrgba(0,0,0,0.2);box-shadow:04px10pxrgba(0,0,0,0.2);}#soulmate.soulmate-type-container{border-top:1pxsolid#ddd;}#soulmate.soulmate-type-container:first-child{border-top:none;}#soulmate.soulmate-type-suggestions{border-left:1pxsolid#ddd;float:right;list-style:none;padding:5px0;width:490px;letter-spacing:0.5px;}#soulmate.soulmate-suggestion{color:#111;cursor:pointer;font-weight:500;font-size:13px;padding:5px06px12px;text-decoration:none;}#soulmate.soulmate-suggestion.focus{color:white;margin-left:-1px;margin-right:-1px;padding-left:13px;position:relative;text-shadow:01px1px#32629b;z-index:1;-webkit-box-shadow:01px2pxrgba(0,0,0,0.3);-moz-box-shadow:01px2pxrgba(0,0,0,0.3);-khtml-box-shadow:01px2pxrgba(0,0,0,0.3);-ms-box-shadow:01px2pxrgba(0,0,0,0.3);-o-box-shadow:01px2pxrgba(0,0,0,0.3);box-shadow:01px2pxrgba(0,0,0,0.3);background:#545454;background:-moz-linear-gradient(top,#5454540,#444444100%);background:-webkit-gradient(linear,00,0100%,from(#545454),to(#444444));-ms-filter:"progid: DXImageTransform.Microsoft.gradient(startColorstr=#545454,endColorstr=#444444)";filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#545454,endColorstr=#444444);}#soulmate.soulmate-type{background-color:white;color:#333;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:11px;letter-spacing:0.5px;margin-right:490px;padding:10px10px010px;text-align:right;text-transform:capitalize;vertical-align:top;-webkit-border-radius:5px;-moz-border-radius:5px;-ms-border-radius:5px;-o-border-radius:5px;-khtml-border-radius:5px;border-radius:5px;zoom:1;}#soulmate.soulmate-type:before,#soulmate.soulmate-type:after{content:"";display:table;}#soulmate.soulmate-type:after{clear:both;}
最後,我們來裝飾查詢門面吧。
增加一個 controller
$ rails g controller home index
讓網站的 root 指向這個 home controller & index action
routes.rb
1
root`home#index`
接著設計一下 view 的畫面
index.html.erb
123456
<divclass="container"><h2>SearchNounsandVerbs</h2> <%= form_tag do %> <%= text_field_tag "search", nil, placeholder: "Search" %> <% end %></div>
varready=function(){varrender,select;render=function(term,data,type){returnterm;}select=function(term,data,type){// populate our search form with the autocomplete result$('#search').val(term);// hide our autocomplete results$('ul#soulmate').hide();// then redirect to the result's link // remember we have the link in the 'data' metadatareturnwindow.location.href=data.link}$('#search').soulmate({url:'/autocomplete/search',types:['nouns','verbs'],renderCallback:render,selectCallback:select,minQueryLength:2,maxResults:5})}// when our document is ready, call our ready function$(document).ready(ready);// if using turbolinks, listen to the page:load event and fire our ready function$(document).on('page:load',ready);