Class: Binda::FieldGroupsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/binda/field_groups_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #after_sign_out_path_for

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/binda/field_groups_controller.rb', line 23

def create
  @field_group = @structure.field_groups.build(field_group_params)

  if @field_group.save
    reset_field_settings_cache
    redirect_to structure_field_group_path( @structure.slug, @field_group.slug ), notice: 'Field group was successfully created.'
  else
    redirect_to new_structure_field_group_path( @structure.slug ), flash: { alert: @field_group.errors }
  end
end

#destroyObject



49
50
51
52
53
# File 'app/controllers/binda/field_groups_controller.rb', line 49

def destroy
  @field_group.destroy
  reset_field_settings_cache
  redirect_to structure_path( @structure.slug ), notice: 'Field group was successfully destroyed.'
end

#editObject



20
21
# File 'app/controllers/binda/field_groups_controller.rb', line 20

def edit
end

#indexObject



8
9
10
# File 'app/controllers/binda/field_groups_controller.rb', line 8

def index
  redirect_to structure_field_group_path( @structure.slug )
end

#newObject



16
17
18
# File 'app/controllers/binda/field_groups_controller.rb', line 16

def new
  @field_group = @structure.field_groups.build()
end

#showObject



12
13
14
# File 'app/controllers/binda/field_groups_controller.rb', line 12

def show
  redirect_to action: :edit
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/binda/field_groups_controller.rb', line 34

def update
  # Add nested classes
  add_new_field_settings
  add_new_choices
  check_if_needs_to_update_choices

  # Update the other ones
  if @field_group.update(field_group_params)
    reset_field_settings_cache
    redirect_to structure_field_group_path( @structure.slug, @field_group.slug ), notice: 'Field group was successfully updated.'
  else
    redirect_to edit_structure_field_group_path( @structure.slug, @field_group.slug ), flash: { alert: @field_group.errors }
  end
end