Sha256: 812328ddab7cfd92f6c624bd67ce630526a6789035c9dcb5153c700f283c4dfb

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

module SharedEngine
  class RespondWithUsersController < SharedEngine::ApplicationController
    respond_to :json, :xml

    self.responder = ActsAsApi::Responder

    def index
      @users = User.all.sort_by(&:first_name)
      respond_with @users, api_template: params[:api_template].to_sym, root: :users
    end

    def index_no_root_no_order
      @users = User.all.to_a
      respond_with @users, api_template: params[:api_template].to_sym
    end

    def index_meta
      @users = User.all.to_a
      meta_hash = { page: 1, total: 999 }
      respond_with @users, api_template: params[:api_template].to_sym, root: :users, meta: meta_hash
    end

    def index_relation
      @users = User.limit(100).sort_by(&:first_name)
      respond_with @users, api_template: params[:api_template].to_sym
    end

    def show
      @user = User.find(params[:id])
      # root: :user is only used here because we need it for the node name of the MongoUser model
      respond_with @user, api_template: params[:api_template].to_sym, root: :user
    end

    def show_meta
      @user = User.find(params[:id])
      meta_hash = { page: 1, total: 999 }
      # root: :user is only used here because we need it for the node name of the MongoUser model
      respond_with @user, api_template: params[:api_template].to_sym, root: :user, meta: meta_hash
    end

    def show_default
      @user = User.find(params[:id])
      respond_with @user
    end

    def show_prefix_postfix
      @user = User.find(params[:id])
      # root: :user is only used here because we need it for the node name of the MongoUser model
      respond_with @user, api_template: { template: params[:api_template], prefix: params[:api_prefix], postfix: params[:api_postfix] }, root: :user
    end

    def create
      @user = User.new(params[:user].permit!)

      if @user.save
        respond_with @user, api_template: params[:api_template]
      else
        respond_with @user
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts_as_api-1.0.1 spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb
acts_as_api-1.0.0 spec/shared_engine/app/controllers/shared_engine/respond_with_users_controller.rb