Class: TypeStation::Admin::EntitiesController

Inherits:
TypeStation::AdminController show all
Defined in:
app/controllers/type_station/admin/entities_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/type_station/admin/entities_controller.rb', line 5

def create
  @entity = Mongoid::Factory.build TypeStation::Entity, '_type' => params[:_type].classify

  if params[:parent_id]
    parent_entity = TypeStation::Entity.find(params[:parent_id])
    @entity.parent = parent_entity
  end

  if @entity.update_contents(contents)
    render json: { status: :success, entity: @entity }, status: :ok
  else
    render json: @entity.errors, status: :unprocessable_entity
  end
end

#destroyObject



34
35
36
37
38
39
40
41
42
# File 'app/controllers/type_station/admin/entities_controller.rb', line 34

def destroy
  @entity = TypeStation::Entity.find(params[:id])

  if @entity.delete
    render json: { status: :success }, status: :ok
  else
    render json: @entity.errors, status: :unprocessable_entity
  end
end

#updateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/type_station/admin/entities_controller.rb', line 20

def update
  @entity = TypeStation::Entity.find(params[:id])

  if params[:direction]
    @entity.move_entity params[:direction]
  end

  if @entity.update_contents(contents)
    render json: { status: :success }, status: :ok
  else
    render json: @entity.errors, status: :unprocessable_entity
  end
end