Class: EngineRoom::FieldsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /fields



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/engine_room/fields_controller.rb', line 47

def create
  @field = Field.new(params[:field])
  @section = Section.find(params[:section_id])

  if(params[:s_action]=='reload')
    return reload_new
  end

  if @field.save
    flash[:notice] = 'Field was successfully created.'
    redirect_to edit_engine_room_section_url(@section.id)
  else
    render :action => :new
  end
end

#destroyObject

DELETE /fields/1



83
84
85
86
87
88
89
90
91
# File 'app/controllers/engine_room/fields_controller.rb', line 83

def destroy
  @field = Field.find(params[:id])
  @field.destroy

  flash[:notice] = 'Field was successfully deleted.'

  section_id = params[:section_id]
  redirect_to edit_engine_room_section_url(section_id)
end

#editObject

GET /fields/1/edit



38
39
40
41
42
43
44
# File 'app/controllers/engine_room/fields_controller.rb', line 38

def edit
  @field = Field.find(params[:id])
  @section = Section.find(params[:section_id])

  add_crumb(@section.name.titleize, edit_engine_room_section_path(@section.id))
  add_crumb('Edit Field', edit_engine_room_section_field_path(@section, @field.id))
end

#indexObject

GET /sections



17
18
19
20
# File 'app/controllers/engine_room/fields_controller.rb', line 17

def index
  @fields = Field.all
  # index.html.erb
end

#init_sectionsObject



10
11
12
13
14
# File 'app/controllers/engine_room/fields_controller.rb', line 10

def init_sections
  @sections = Section.all
  @layout = 'columns'
  @sidebar = 'engine_room/sections'
end

#newObject

GET /fields/new



29
30
31
32
33
34
35
# File 'app/controllers/engine_room/fields_controller.rb', line 29

def new
  @field = Field.new
  @section = Section.find(params[:section_id])

  add_crumb(@section.name.titleize, edit_engine_room_section_path(@section.id))
  add_crumb 'New Field'
end

#showObject

GET /fields/1



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

def show
  @field = Field.find(params[:id])
  # show.html.erb
end

#updateObject

PUT /fields/1



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/engine_room/fields_controller.rb', line 64

def update
  @field = Field.find(params[:id])
  @section = Section.find(params[:section_id])

  if(params[:s_action]=='reload')
    return reload_edit
  end

  @field.options = nil # remove all old options
  if @field.update_attributes(params[:field])
    flash[:notice] = 'Field was successfully updated.'
    redirect_to edit_engine_room_section_url(@section.id)
  else
    #render :action => :edit
    reload_edit
  end
end