Skip to content

Instantly share code, notes, and snippets.

@mokevnin
Created June 27, 2012 08:56
Show Gist options
  • Select an option

  • Save mokevnin/3002574 to your computer and use it in GitHub Desktop.

Select an option

Save mokevnin/3002574 to your computer and use it in GitHub Desktop.
class Api::SearchController < ApplicationController
##
# Search
#
# @example [Request] GET /search?q=name&page=2
# @example [Response] total: <count>, episodes: [<episode>, <episode>, ...]
#
# @overload show(q, page)
# @param [String] q Query string
# @param [Integer] page
#
#
def show
episodes = Episode.search params[:q], :with => {:next_episode_id => 0},
:per_page => 16, :page => params[:page], :order => :created_at, :sort_mode => :desc
data = {
:total => episodes.total_entries,
:episodes => episodes.compact.map {|e| EpisodePresenter.to_hash(e) }
}
render :json => data
rescue Riddle::ConnectionError => e
notify_hoptoad e
render :json => %q({"total":0,"episodes":[]})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment