New Candidate
+ + <% if flash[:error].present? %> +<%= "#{k}: #{v}" %>
+ <% end %> +diff --git a/app/controllers/recruiter_controller.rb b/app/controllers/recruiter_controller.rb
index 0b51426..a6d05c8 100644
--- a/app/controllers/recruiter_controller.rb
+++ b/app/controllers/recruiter_controller.rb
@@ -7,9 +7,18 @@ class RecruiterController < ApplicationController
def new
@candidate = Candidate.new
+ render :form
end
def create
+ @candidate = Candidate.create(candidate_params.merge(recruiter_id: current_recruiter.id))
+
+ if @candidate.persisted?
+ redirect_to recruiter_path, flash: { notice: "Sucessfully created candidate #{@candidate.name}" }
+ else
+ flash[:error] = "Failed to save Candidate."
+ render :form
+ end
end
def login
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index de6be79..4c7737c 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,2 +1,12 @@
module ApplicationHelper
+ def experience_options val
+ options_for_select([
+ ["Please Select", ""],
+ ["0-3 Years", "0-3"],
+ ["4-6 Years", "4-6"],
+ ["7-9 Years", "7-9"],
+ ["10-14 Years", "10-14"],
+ ["15+ Years", "15+"]
+ ], disabled: "-", selected: (val.blank? ? '' : val))
+ end
end
diff --git a/app/models/candidate.rb b/app/models/candidate.rb
index 482864a..b219635 100644
--- a/app/models/candidate.rb
+++ b/app/models/candidate.rb
@@ -4,11 +4,14 @@ class Candidate < ApplicationRecord
has_many :answers
belongs_to :recruiter, class_name: "User"
- before_create :generate_test_hash
+ before_validation(:generate_test_hash, on: :create)
+ validates_presence_of :name
+ validates_presence_of :email
+ validates_presence_of :experience
validates_presence_of :recruiter_id
- validates_presence_of :test_hash
- validates_uniqueness_of :test_hash
+ validates :email, uniqueness: true, presence: true, email_format: true
+ validates :test_hash, uniqueness: true, presence: true
def submitted_answers
answers.where(submitted: true)
diff --git a/app/validators/email_format_validator.rb b/app/validators/email_format_validator.rb
new file mode 100644
index 0000000..cc2ec71
--- /dev/null
+++ b/app/validators/email_format_validator.rb
@@ -0,0 +1,16 @@
+class EmailFormatValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ # EMAIL regex test
+ # (comma seperated) [any word combo] AT [any word combo] DOT [2 or more]
+ # me@no.yes.x == invalid
+ # some.thing+two@sub.domain.name == valid
+
+ results = value.to_s.split(',').map do |v|
+ (v.strip =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i) || v.strip.blank?
+ end
+
+ if results.include?(false)
+ record.errors[attribute] << (options[:message] || "is not formatted properly: #{value}")
+ end
+ end
+end
diff --git a/app/views/recruiter/form.html.erb b/app/views/recruiter/form.html.erb
new file mode 100644
index 0000000..e0b7029
--- /dev/null
+++ b/app/views/recruiter/form.html.erb
@@ -0,0 +1,32 @@
+ <%= "#{k}: #{v}" %>New Candidate
+
+ <% if flash[:error].present? %>
+