Class: Pulitzer::PartialTypesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pulitzer/partial_types_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/pulitzer/partial_types_controller.rb', line 16

def create
  @free_form_section_type = Pulitzer::FreeFormSectionType.find partial_type_params[:free_form_section_type_id]
  @partial_type = @free_form_section_type.partial_types.create partial_type_params
  if @partial_type && @partial_type.errors.empty?
    Pulitzer::CreateFreeFormSectionPartials.new(@partial_type).call
    render partial: 'show_wrapper', locals: { partial_type: @partial_type }
  else
    render partial: 'new', locals: { partial_type: @partial_type }
  end
end

#destroyObject



42
43
44
45
46
# File 'app/controllers/pulitzer/partial_types_controller.rb', line 42

def destroy
  Pulitzer::DestroyFreeFormSectionPartials.new(@partial_type).call
  @partial_type.destroy
  head :ok
end

#editObject



31
32
33
# File 'app/controllers/pulitzer/partial_types_controller.rb', line 31

def edit
  render partial: 'form', locals: { partial_type: @partial_type }
end

#indexObject



4
5
6
7
8
# File 'app/controllers/pulitzer/partial_types_controller.rb', line 4

def index
  @ffst = Pulitzer::FreeFormSectionType.find(params[:ffst_id])
  @partial_types = @ffst.partial_types
  render partial: 'index', locals: { ffst: @ffst }
end

#newObject



10
11
12
13
14
# File 'app/controllers/pulitzer/partial_types_controller.rb', line 10

def new
  @ffst = Pulitzer::FreeFormSectionType.find(params[:ffst_id])
  @partial_type = @ffst.partial_types.build
  render partial: 'new', locals: { ffst: @ffst, partial_type: @partial_type }
end

#showObject



27
28
29
# File 'app/controllers/pulitzer/partial_types_controller.rb', line 27

def show
  render partial: 'show', locals: { partial_type: @partial_type }
end

#updateObject



35
36
37
38
39
40
# File 'app/controllers/pulitzer/partial_types_controller.rb', line 35

def update
  old_label = @partial_type.label
  @partial_type.update_attributes(partial_type_params)
  Pulitzer::UpdateFreeFormSectionPartials.new(@partial_type, old_label).call
  render partial: 'show', locals: { partial_type: @partial_type }
end

#update_allObject



48
49
50
51
52
53
54
55
# File 'app/controllers/pulitzer/partial_types_controller.rb', line 48

def update_all
  partial_types = Pulitzer::PartialType.find params[:partial_type]
  partial_types.each do |pt|
    new_sort_order = params[:partial_type].index(pt.id.to_s)
    pt.update_attribute(:sort_order, new_sort_order)
  end
  head :ok
end