Class: Cms::Admin::FormFieldsController

Inherits:
BaseController show all
Defined in:
app/controllers/cms/admin/form_fields_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
# File 'app/controllers/cms/admin/form_fields_controller.rb', line 19

def create
  @field = @page.form_fields.build(field_params)

  if @field.save
    redirect_to admin_page_form_fields_path(@page), notice: t("cms.notices.field_added")
  else
    render :new, status: :unprocessable_content
  end
end

#destroyObject



39
40
41
42
# File 'app/controllers/cms/admin/form_fields_controller.rb', line 39

def destroy
  @field.destroy
  redirect_to admin_page_form_fields_path(@page), notice: t("cms.notices.field_removed")
end

#editObject



17
# File 'app/controllers/cms/admin/form_fields_controller.rb', line 17

def edit; end

#indexObject



9
10
11
# File 'app/controllers/cms/admin/form_fields_controller.rb', line 9

def index
  @fields = @page.form_fields.ordered
end

#newObject



13
14
15
# File 'app/controllers/cms/admin/form_fields_controller.rb', line 13

def new
  @field = @page.form_fields.build(position: @page.form_fields.count)
end

#sortObject



44
45
46
47
48
49
# File 'app/controllers/cms/admin/form_fields_controller.rb', line 44

def sort
  Array(params[:field_ids]).each_with_index do |id, position|
    @page.form_fields.find(id).update!(position: position)
  end
  head :ok
end

#updateObject



29
30
31
32
33
34
35
36
37
# File 'app/controllers/cms/admin/form_fields_controller.rb', line 29

def update
  @field.assign_attributes(field_params)

  if @field.save
    redirect_to admin_page_form_fields_path(@page), notice: t("cms.notices.field_updated")
  else
    render :edit, status: :unprocessable_content
  end
end