Created
June 27, 2012 08:56
-
-
Save mokevnin/3002574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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