Sha256: d5b135953904952789d4814c2707e1dbb88e39341b2cd7501ac945ad50b690b6

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 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_meta
      @users = User.all
      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])

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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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