Class: Census::DataGroupsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/census/data_groups_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/census/data_groups_controller.rb', line 13

def create
  @data_group = DataGroup.new(params[:data_group])
  
  if @data_group.save
    flash[:notice] = "Created #{@data_group.name}"
    redirect_to census_admin_path
  else
    render :action => 'new', :status => :unprocessable_entity
  end
end

#destroyObject



39
40
41
42
43
44
# File 'app/controllers/census/data_groups_controller.rb', line 39

def destroy
  @data_group = DataGroup.find(params[:id])
  @data_group.destroy
  flash[:notice] = "Deleted #{@data_group.name}"
  redirect_to census_admin_path
end

#editObject



24
25
26
# File 'app/controllers/census/data_groups_controller.rb', line 24

def edit
  @data_group = DataGroup.find(params[:id])
end

#indexObject



5
6
7
# File 'app/controllers/census/data_groups_controller.rb', line 5

def index
  @data_groups = DataGroup.all
end

#newObject



9
10
11
# File 'app/controllers/census/data_groups_controller.rb', line 9

def new
  @data_group = DataGroup.new(params[:data_group])
end

#sortObject



46
47
48
49
50
51
52
53
# File 'app/controllers/census/data_groups_controller.rb', line 46

def sort
  group_positions = params[:data_group].to_a
  DataGroup.all.each_with_index do |group, i|
    group.position = group_positions.index(group.id.to_s) + 1
    group.save
  end
  render :text => 'ok'
end

#updateObject



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/census/data_groups_controller.rb', line 28

def update
  @data_group = DataGroup.find(params[:id])
  
  if @data_group.update_attributes(params[:data_group])
    flash[:notice] = "Saved #{@data_group.name}"
    redirect_to census_admin_path
  else
    render :action => 'edit', :status => :unprocessable_entity
  end
end