Class: Layered::Assistant::SkillsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @skill = Skill.new(skill_params)
  @skill.owner = l_ui_current_user

  if @skill.save
    redirect_to layered_assistant.skills_path, notice: "Skill was successfully created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



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

def destroy
  if @skill.destroy
    redirect_to layered_assistant.skills_path, notice: "Skill was successfully deleted."
  else
    redirect_to layered_assistant.skills_path, alert: "Skill could not be deleted: #{@skill.errors.full_messages.to_sentence}."
  end
rescue ActiveRecord::InvalidForeignKey
  redirect_to layered_assistant.skills_path, alert: "Skill could not be deleted because it is assigned to assistants."
end

#editObject



27
28
29
# File 'app/controllers/layered/assistant/skills_controller.rb', line 27

def edit
  @page_title = "Edit skill"
end

#indexObject



6
7
8
9
# File 'app/controllers/layered/assistant/skills_controller.rb', line 6

def index
  @page_title = "Skills"
  @pagy, @skills = pagy(scoped(Skill).by_name)
end

#newObject



11
12
13
14
# File 'app/controllers/layered/assistant/skills_controller.rb', line 11

def new
  @page_title = "New skill"
  @skill = Skill.new
end

#updateObject



31
32
33
34
35
36
37
# File 'app/controllers/layered/assistant/skills_controller.rb', line 31

def update
  if @skill.update(skill_params)
    redirect_to layered_assistant.skills_path, notice: "Skill was successfully updated."
  else
    render :edit, status: :unprocessable_entity
  end
end