volunteers_controller.rb 1.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
  end

  def edit; end

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

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

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

  private

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

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