Class: Databaseformalizer::EntitiesController

Inherits:
ApplicationController
  • Object
show all
Includes:
Databaseformalizer
Defined in:
app/controllers/databaseformalizer/entities_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /entities POST /entities.json



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/databaseformalizer/entities_controller.rb', line 56

def create
  @entity = Entity.new(params[:databaseformalizer_entity])
  @entity.attr_vals.clear
  EntitiesHelper.setAttrVals(params[:attr_vals], @entity)
  
  respond_to do |format|
    if @entity.save
      format.html { redirect_to @entity, notice: 'Entity was successfully created.' }
      format.json { render json: @entity, status: :created, location: @entity }
    else
      format.html { render action: "new" }
      format.json { render json: @entity.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /entities/1 DELETE /entities/1.json



93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/databaseformalizer/entities_controller.rb', line 93

def destroy
  
  @entity = Entity.find(params[:id])
  @entity.destroy
  
  respond_to do |format|
    format.html { redirect_to databaseformalizer_entities_url }
    format.json { head :no_content }
  end
end

#editObject

GET /entities/1/edit



49
50
51
52
# File 'app/controllers/databaseformalizer/entities_controller.rb', line 49

def edit
  @entity = Entity.find(params[:id])
  @all_entityDefs = EntityDef.all
end

#indexObject

GET /entities GET /entities.json



7
8
9
10
11
12
13
14
15
# File 'app/controllers/databaseformalizer/entities_controller.rb', line 7

def index
  @entities = Entity.find(:all, :limit=>100)
  EntitiesHelper.setModelGraph("public/UMLmodel.png")
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @entities }
  end
end

#newObject

GET /entities/new GET /entities/new.json



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/databaseformalizer/entities_controller.rb', line 30

def new
  @entity = Entity.new
  
  if params[:entity_def] != nil
    @all_entityDefs = EntityDef.find_all_by_entity_def_name(params[:entity_def])
    @entity.entity_def = @all_entityDefs.first
    @type = params[:entity_def]
  else
    @all_entityDefs = EntityDef.all
    @type = "Entity"
  end
  respond_to do |format|
    format.html # new.html.erbe
    format.json { render json: @entity }
    format.js { @entity }
  end
end

#showObject

GET /entities/1 GET /entities/1.json



19
20
21
22
23
24
25
26
# File 'app/controllers/databaseformalizer/entities_controller.rb', line 19

def show
  @entity = Entity.find(params[:id])
  
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @entity }
  end
end

#updateObject

PUT /entities/1 PUT /entities/1.json



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/databaseformalizer/entities_controller.rb', line 74

def update
  @entity = Entity.find(params[:id])
  @entity.attr_vals.clear
  EntitiesHelper.setAttrVals(params[:attr_vals], @entity)
  @entity.attributes = params[:databaseformalizer_entity]
  
  respond_to do |format|
    if @entity.save
      format.html { redirect_to @entity, notice: 'Entity was successfully updated.'}
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @entity.errors, status: :unprocessable_entity }
    end
  end
end