Class: Layered::Assistant::AssistantsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/layered/assistant/assistants_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/layered/assistant/assistants_controller.rb', line 19

def create
  @assistant = Assistant.new(assistant_params.except(:persona_id, :skill_ids))
  @assistant.owner = l_ui_current_user
  @assistant.persona = scoped(Persona).find(assistant_params[:persona_id]) if assistant_params[:persona_id].present?

  if @assistant.save
    assign_skills
    redirect_to layered_assistant.assistants_path, notice: "Assistant was successfully created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



49
50
51
52
# File 'app/controllers/layered/assistant/assistants_controller.rb', line 49

def destroy
  @assistant.destroy
  redirect_to layered_assistant.assistants_path, notice: "Assistant was successfully deleted."
end

#editObject



32
33
34
# File 'app/controllers/layered/assistant/assistants_controller.rb', line 32

def edit
  @page_title = "Edit assistant"
end

#indexObject



9
10
11
12
# File 'app/controllers/layered/assistant/assistants_controller.rb', line 9

def index
  @page_title = "Assistants"
  @pagy, @assistants = pagy(scoped(Assistant).includes(:persona).by_name)
end

#newObject



14
15
16
17
# File 'app/controllers/layered/assistant/assistants_controller.rb', line 14

def new
  @page_title = "New assistant"
  @assistant = Assistant.new
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/layered/assistant/assistants_controller.rb', line 36

def update
  if assistant_params.key?(:persona_id)
    @assistant.persona = assistant_params[:persona_id].present? ? scoped(Persona).find(assistant_params[:persona_id]) : nil
  end

  if @assistant.update(assistant_params.except(:persona_id, :skill_ids))
    assign_skills
    redirect_to layered_assistant.assistants_path, notice: "Assistant was successfully updated."
  else
    render :edit, status: :unprocessable_entity
  end
end