class VolunteersController < ApplicationController
  def index
    @volunteers = Volunteer.all
  end

  def new
    @volunteer = Volunteer.new
  end

  def create
    @volunteer = Volunteer.create(volunteer_params)
    respond_to do |format|
      format.html { redirect_to root_path }
      format.js
    end
    if @volunteer.save
      flash[:success] = 'Welcome, #{@volunteer.first_name}!'
    else
      render('new')
    end
  end

  private

  def volunteer_params
    params.require(:volunteer).permit(:firstname, :lastname, :email, :zip, :mobile, :project)
  end
end
