Class: Crm::Scheduler::BookingPageQuestionsController

Inherits:
CrmController
  • Object
show all
Defined in:
app/controllers/crm/scheduler/booking_page_questions_controller.rb

Overview

Controller: booking page questions.

Instance Method Summary collapse

Instance Method Details

#createvoid

This method returns an undefined value.

Creates a booking question for #find_booking_page, appended after
the existing questions.



12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/crm/scheduler/booking_page_questions_controller.rb', line 12

def create
  @question = @booking_page.scheduler_booking_questions.build(question_params)
  @question.position = @booking_page.scheduler_booking_questions.maximum(:position).to_i + 1

  if @question.save
    redirect_to scheduler_admin_booking_page_path(@booking_page), notice: 'Question added.'
  else
    redirect_to scheduler_admin_booking_page_path(@booking_page), alert: @question.errors.full_messages.join(', ')
  end
end

#destroyvoid

This method returns an undefined value.

Deletes the question loaded by #find_question.



37
38
39
40
# File 'app/controllers/crm/scheduler/booking_page_questions_controller.rb', line 37

def destroy
  @question.destroy
  redirect_to scheduler_admin_booking_page_path(@booking_page), notice: 'Question removed.'
end

#reordervoid

This method returns an undefined value.

Bulk-updates question positions from a {id => position} map, for
drag-and-drop reordering.



46
47
48
49
50
51
52
# File 'app/controllers/crm/scheduler/booking_page_questions_controller.rb', line 46

def reorder
  positions = params[:positions] || {}
  positions.each do |id, pos|
    @booking_page.scheduler_booking_questions.where(id: id).update_all(position: pos.to_i)
  end
  head :ok
end

#updatevoid

This method returns an undefined value.

Updates the question loaded by #find_question.



26
27
28
29
30
31
32
# File 'app/controllers/crm/scheduler/booking_page_questions_controller.rb', line 26

def update
  if @question.update(question_params)
    redirect_to scheduler_admin_booking_page_path(@booking_page), notice: 'Question updated.'
  else
    redirect_to scheduler_admin_booking_page_path(@booking_page), alert: @question.errors.full_messages.join(', ')
  end
end