class PlayersController < ApplicationController

  include QuizHelperMethods

  skip_before_action :require_player!

  # GET /player
  def new
    reset_session
    Current.player = nil

    @player = Player.new
  end


  # POST /player
  def create
    @player = Player.new(player_params.merge(locale: I18n.locale))


    respond_to do |format|
      if @player.save
        session[:player_id] = @player.id
        format.html { redirect_to url_for(controller: 'questions', action: 'show', id: 1) }
      else
        format.html { render :new, status: :unprocessable_entity }
      end
    end
  end


private


  # Only allow a list of trusted parameters through.
  def player_params
    params.require(:player).permit(
      :name
    )
  end

end
