Class: Crm::Scheduler::BookingPageQuestionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/crm/scheduler/booking_page_questions_controller.rb', line 7

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

#destroyObject



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

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

#reorderObject



31
32
33
34
35
36
37
# File 'app/controllers/crm/scheduler/booking_page_questions_controller.rb', line 31

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

#updateObject



18
19
20
21
22
23
24
# File 'app/controllers/crm/scheduler/booking_page_questions_controller.rb', line 18

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