Class: Binda::StructuresController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #after_sign_out_path_for

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/binda/structures_controller.rb', line 22

def create
  @structure = Structure.new(structure_params)

  if @structure.save
    redirect_to structure_path( @structure.slug ), notice: "#{ @structure.name.capitalize } structure was successfully created."
  else
    render :new
  end
end

#destroyObject



44
45
46
47
# File 'app/controllers/binda/structures_controller.rb', line 44

def destroy
  @structure.destroy
  redirect_to structures_url, notice: "#{ @structure.name.capitalize } structure was successfully destroyed."
end

#editObject



19
20
# File 'app/controllers/binda/structures_controller.rb', line 19

def edit
end

#fields_updateObject



49
50
51
# File 'app/controllers/binda/structures_controller.rb', line 49

def fields_update
  redirect_to :back, notice: "#{ @structure.name.capitalize } structure was successfully updated."
end

#indexObject



7
8
9
# File 'app/controllers/binda/structures_controller.rb', line 7

def index
  @structures = Structure.order('position').all.page params[:page]
end

#newObject



15
16
17
# File 'app/controllers/binda/structures_controller.rb', line 15

def new
  @structure = Structure.new
end

#showObject



11
12
13
# File 'app/controllers/binda/structures_controller.rb', line 11

def show
  redirect_to action: :edit
end

#sortObject



53
54
55
56
57
58
# File 'app/controllers/binda/structures_controller.rb', line 53

def sort
  params[:structure].each_with_index do |id, i|
    Structure.find( id ).update({ position: i + 1 })
  end
  render js: "$('##{params[:id]}').sortable('option', 'disabled', false); $('.popup-warning').addClass('popup-warning--hidden'); $('.sortable').removeClass('sortable--disabled')"
end

#sort_indexObject



60
61
62
# File 'app/controllers/binda/structures_controller.rb', line 60

def sort_index
  @structures = Structure.order('position').all.page params[:page]
end

#updateObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/binda/structures_controller.rb', line 32

def update
  # Create new fields if any
  add_new_field_groups

  # Update the other ones
  if @structure.update(structure_params)
    redirect_to structure_path( @structure.slug ), notice: "#{ @structure.name.capitalize } structure was successfully updated."
  else
    render :edit
  end
end