Class: EngineRoom::ModelsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/engine_room/models_controller.rb

Instance Method Summary collapse

Instance Method Details

#check_model_nameObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/engine_room/models_controller.rb', line 13

def check_model_name
  @modelname = params[:modelname]
  begin
    @model = get_model(@modelname)
  rescue NameError
    flash[:error] = "No model with given name was found!"
    redirect_to :action => :overview
  end
end

#editObject



68
69
70
# File 'app/controllers/engine_room/models_controller.rb', line 68

def edit
  @element = @model.find(params[:id])
end

#indexObject



53
54
55
56
# File 'app/controllers/engine_room/models_controller.rb', line 53

def index
  @elements = @model.find(:all)
  add_crumb @modelname, {:controller => 'engine_room/models', :action => :index, :modelname => @modelname}
end

#newObject



62
63
64
65
66
# File 'app/controllers/engine_room/models_controller.rb', line 62

def new
  @element = @model.new
  add_crumb @modelname, {:controller => 'engine_room/models', :action => :index, :modelname => @modelname}
  add_crumb "Create New #{@modelname}"
end

#overviewObject



24
25
26
# File 'app/controllers/engine_room/models_controller.rb', line 24

def overview
  @sections = Section.all
end

#overview2Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/engine_room/models_controller.rb', line 29

def overview2
  @models = []
  missing_models = []
  missing_tables = []
  Section.all.each do |section|
    begin
      model = get_model(section.model_name)
      if model.table_exists?
        @models << model
      else
        missing_tables << section.model_name
      end
    rescue NameError
      missing_models << section.model_name
    end
  end
  
  flash_alert = ""
  flash_alert += "Table(s) not found: '#{missing_tables.uniq.join("', '")}'. " unless missing_tables.empty?
  flash_alert += "Model(s) not found: '#{missing_models.uniq.join("', '")}'." unless missing_models.empty?
  flash[:alert] = flash_alert unless flash_alert.empty?
end

#showObject



58
59
60
# File 'app/controllers/engine_room/models_controller.rb', line 58

def show
  @element = @model.find(params[:id])
end

#updateObject



72
73
74
75
76
77
78
79
80
# File 'app/controllers/engine_room/models_controller.rb', line 72

def update
  @element = @model.find(params[:id])
  if @element.update_attributes(params[@modelname.downcase])
    flash[:notice] = "#{@modelname} successfully updated."
    redirect_to :action => :edit
  else
    render 'edit'
  end
end