Class: Goldencobra::Api::V3::ArticlesController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Goldencobra::Api::V3::ArticlesController
- Defined in:
- app/controllers/goldencobra/api/v3/articles_controller.rb
Instance Method Summary collapse
Instance Method Details
#index ⇒ json
map{ |c| [c.parent_path, c.id] }
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/goldencobra/api/v3/articles_controller.rb', line 14 def index if params[:article_ids].present? index_with_ids else @articles = Goldencobra::Article.active @articles = @articles.tagged_with(params[:tags].split(","), on: :tags) if params[:tags].present? @articles = @articles.tagged_with(params[:no_tags].split(","), exclude: true, on: :tags) if params[:no_tags].present? respond_to do |format| format.json do render json: Oj.dump( { articles: articles_as_json }, mode: :compat ) end # Returns all publicly visible, active Articles format.xml do @articles = Goldencobra::Article. new. ( Goldencobra::Article.active, nil ) end end end end |
#index_with_ids ⇒ json
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/goldencobra/api/v3/articles_controller.rb', line 77 def index_with_ids article_ids = params[:article_ids] cache_key ||= ["indexarticles", article_ids] articles = Rails.cache.fetch(cache_key) do Goldencobra::Article.where("id IN (?)", article_ids) end respond_to do |format| format.json do if params[:methods].present? render json: Oj.dump( articles, each_serializer: Goldencobra::ArticleCustomSerializer, scope: params[:methods] ) else render json: Oj.dump(articles) end end end end |
#show ⇒ json
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/goldencobra/api/v3/articles_controller.rb', line 50 def show respond_to do |format| format.json do if params[:methods].present? render json: Oj.dump( @article.as_json, serializer: Goldencobra::ArticleCustomSerializer, scope: params[:methods] ) else render json: Oj.dump(@article.as_json) end end end end |