!!! %html{ :lang => 'en' } %head %link{:href => "stylesheets/stylesheet.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}/ %body %img{:src => "images/picky.png"}/ %p %a{:href => "http://floere.github.com/picky"} To the Picky Homepage \/ %a{:href => '/' } Back to the example .content %h1 Already made it this far? You're good! %p I think you're ready for configuring me for your own purposes. %h2 Configuring the Picky client. %p There are two places where you configure the Picky client: %ol %li %a{ :href => '#controller' } In the controller. (client to Picky server) %li %a{ :href => '#view' } In the view. (javascript client interface) %h2#controller Controller %p Open the file %strong app.rb and take a peek inside. %p First you need both a client instance for a %strong full or a %strong live search depending on what you need (Full gets results with IDs, Live without and is used for updating the counter). %p In the example, I called it %strong FullBooks and %strong LiveBooks respectively. %code %pre :preserve FullBooks = Picky::Client::Full.new :host => 'localhost', :port => 8080, :path => '/books/full' LiveBooks = Picky::Client::Live.new :host => 'localhost', :port => 8080, :path => '/books/live' %p Both clients offer the options: %dl %dt %strong host %dd The Picky search server host. %dt %strong port %dd The Picky search server port (see unicorn.rb in the server). %dt %strong path %dd The Picky search path (see app/application.rb in the server for the mapping path => query). %p Then, use these Client instances in your actions. For example like this: %code %pre :preserve get '/search/full' do results = FullBooks.search :query => params[:query], :offset => params[:offset] results.extend Picky::Convenience results.populate_with Book do |book| book.to_s end ActiveSupport::JSON.encode results end %p This part gets a %strong hash with the results: %code %pre results = FullBooks.search :query => params[:query], :offset => params[:offset] %p This part takes the %strong hash and extends it with a few useful and convenient methods: %code %pre results.extend Picky::Convenience %p One of these methods is the %strong populate_with method which takes a %strong model as parameter, and then gets the corresponding %strong model instances for each id in the result. %code %pre :preserve results.populate_with Book do |book| book.to_s end The %strong book.to_s simulates rendering a book. You can do whatever with the book instance if you just return a rendered thing that's supposed to be shown in the front end. %p If you don't want to render in the controller, you can do so in a view. In the controller just call %code %pre results.populate_with Book and then render the books in a view using: %code %pre :preserve results.entries do |book| render book # or book.to_s, or however you like to render the book. end %p At the end, encode the hash in JSON: %code %pre ActiveSupport::JSON.encode results That's it for the controller. %p All the steps in one: %code %pre :preserve FullBooks = Picky::Client::Full.new :host => 'localhost', :port => 8080, :path => '/books/full' LiveBooks = Picky::Client::Live.new :host => 'localhost', :port => 8080, :path => '/books/live' get '/search/full' do results = FullBooks.search :query => params[:query], :offset => params[:offset] results.extend Picky::Convenience results.populate_with Book do |book| book.to_s end ActiveSupport::JSON.encode results end %h2#view View %p The view is even easier. Just add the line %code %pre \= Picky::Helper.cached_interface if you use just one language, or %code %pre \= Picky::Helper.interface :button => 'search', :no_results => 'No results!', :more => 'more' if you use multiple languages. (You'd use the options %pre :button => t(:'search.button'), :no_results => t(:'search.no_results'), :more => t(:'search.more') of course, with proper i18n) The same options can be used for %strong #cached_interface but they will be cached, so you can only set them once and then reused. %p You're almost finished. Take a look at the file %strong views/search.haml where you'll find javascript at the end. It looks something like this: %code %pre :preserve :javascript pickyClient = new PickyClient({ // A full query displays the rendered results. // full: '/search/full', // etc. Just take a look at the possible javascript client options in that file. %p %strong Good luck my friend! *waves several stubby pink tentacles*