class Www::CoursesController < WwwController

  before_filter :load_states, :build_breadcrumb

  def index
    @participant = CourseParticipant.new(params[:course_participant])
    @participant.textcaptcha
  end


  def create
    @participant = CourseParticipant.new(params[:course_participant])
    if @participant.save
      @participant.deliver_register_participant_email
      redirect_to www_courses_url, notice: t('www.courses.create.save_successfully')
    else
      @cities = City.where(state_id: @participant.try(:state_id)).order(:name)
      render :index
    end
  end

  private
    def build_breadcrumb
      add_breadcrumb I18n.t('www.layout.home'), www_root_path
      add_breadcrumb t('www.courses.index.title')
    end

    def load_states
      @states = State.order(:name)
    end

end
