module MongoidApiBase::Actions

Public Instance Methods

create() click to toggle source
# File lib/mongoid-api-base/actions.rb, line 26
def create
  object = build_object
  if object.save
    render json: object.as_json(json_config(:create))
  else
    render json: object.errors, status: :unprocessable_entity
  end
end
destroy() click to toggle source
# File lib/mongoid-api-base/actions.rb, line 44
def destroy
  object = find_object
  if object.destroy
    render nothing: true, status: 204
  else
    render json: object.errors, status: :unprocessable_entity
  end
end
index() click to toggle source
# File lib/mongoid-api-base/actions.rb, line 6
def index
  @chain = resource_class

  apply_scopes_to_chain!
  search_filter_chain!
  paginate_chain!
  set_total_count_header!

  respond_to do |format|
    format.json { render json: @chain.as_json(json_config(:index)) }
    format.csv  { render csv: @chain }
  end
end
show() click to toggle source
# File lib/mongoid-api-base/actions.rb, line 20
def show
  object = find_object
  object = get_object_version(object)
  render json: object.as_json(json_config(:show))
end
update() click to toggle source
# File lib/mongoid-api-base/actions.rb, line 35
def update
  object = find_object
  if object.update_attributes(resource_params)
    render json: object.as_json(json_config(:update))
  else
    render json: object.errors, status: :unprocessable_entity
  end
end