Last active
August 29, 2015 14:03
-
-
Save alexvbush/86970eb4f4aad191ca1d to your computer and use it in GitHub Desktop.
Second iteration of Articles controller.
This file contains 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::Private::ArticlesController < Api::Private::BaseController | |
include ArticlesSearch | |
before_filter :find_or_create_article, except: [:index] | |
PAGE_SIZE = 20 | |
def index | |
@articles = Article.scoped | |
total_pages = 0 | |
page = params[:page] ? params[:page] : 1 | |
if params[:state] == Article::PENDING | |
@articles = Article.pending | |
elsif params[:state] == Article::APPROVED | |
@articles = Article.approved | |
else | |
@articles = @articles.order('articles.created_at DESC') | |
end | |
if params[:query] | |
@articles = articles_search(params[:query], params[:state]) | |
end | |
@articles = @articles.page(page).per_page(PAGE_SIZE) | |
total_pages = @articles.total_pages | |
respond_with @articles, each_serializer: article_serializer, root: 'articles', meta: { total_pages: total_pages } | |
end | |
##### | |
# ... | |
# The rest of the methods ommited | |
# ... | |
##### | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment