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

  def index
    @volunteers = Volunteer.all
  end

  def show; end

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

  def edit; end

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

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

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

  private

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

  def volunteer_params
46
    params.require(:volunteer).permit(:first_name, :last_name, :date_of_birth, :gender, :avatar,
47
48
      :street, :zip, :city, :nationality, :additional_nationality, :email, :phone, :profession,
      :education, :motivation, :experience, :expectations, :strengths, :skills, :interests, :state,
49
      :duration, :man, :woman, :family, :kid, :sport, :creative, :music, :culture, :training,
50
51
52
      :german_course, :adults, :teenagers, :children, :region,
      language_skills_attributes: [
        :id, :language, :level, :_destroy
53
54
55
      ],
      relatives_attributes: [
        :id, :first_name, :last_name, :date_of_birth, :relation, :_destroy
56
57
58
      ],
      schedules_attributes: [
        :id, :day, :time, :available
59
      ])
60
61
  end
end