volunteers_controller.rb 1.48 KB
Newer Older
1
class VolunteersController < ApplicationController
2
  include NestedAttributes
3
4
5
6
7
8
9
10
11
12
  before_action :set_volunteer, only: [:show, :edit, :update, :destroy]

  def index
    @volunteers = Volunteer.all
  end

  def show; end

  def new
    @volunteer = Volunteer.new
13
    @volunteer.schedules << Schedule.build
14
15
16
17
18
19
  end

  def edit; end

  def create
    @volunteer = Volunteer.new(volunteer_params)
20
21
22
23
    if @volunteer.save
      redirect_to @volunteer, notice: t('volunteer_created')
    else
      render :new
24
25
26
27
    end
  end

  def update
28
29
30
31
    if @volunteer.update(volunteer_params)
      redirect_to @volunteer, notice: t('volunteer_updated')
    else
      render :edit
32
33
34
35
36
    end
  end

  def destroy
    @volunteer.destroy
37
    redirect_to volunteers_url, notice: t('volunteer_destroyed')
38
39
40
41
42
43
44
45
46
  end

  private

  def set_volunteer
    @volunteer = Volunteer.find(params[:id])
  end

  def volunteer_params
47
    params.require(:volunteer).permit(:first_name, :last_name, :date_of_birth, :gender, :avatar,
48
49
      :street, :zip, :city, :nationality, :additional_nationality, :email, :phone, :profession,
      :education, :motivation, :experience, :expectations, :strengths, :skills, :interests, :state,
50
      :duration, :man, :woman, :family, :kid, :sport, :creative, :music, :culture, :training,
51
      :german_course, :adults, :teenagers, :children, :region,
52
53
54
      language_skills_attributes: language_skills_attributes,
      relatives_attributes: relatives_attributes,
      schedules_attributes: schedules_attributes)
55
56
  end
end