Skip to content

Instantly share code, notes, and snippets.

View tarynsauer's full-sized avatar

Taryn Sauer tarynsauer

  • Madison, WI
View GitHub Profile
post '/applicants/new' do
updated_params = modify_date_params(params)
@applicant = Applicant.create(updated_params[:applicant])
redirect "/applicants/#{@applicant.id}"
end
post '/applicants/:id' do
applicant = Applicant.find_by_id(params[:id])
updated_params = modify_date_params(params)
applicant.update(updated_params)
class Applicant
include Observable
def update(attributes = {})
self.update(attributes)
if self.save
notify_observers
end
end
def error?(field)
if flash[:errors_list]
flash[:errors_list].include?(field)
else
false
end
end
<% if flash[:notice] %>
<p class="notice"><%= flash[:notice] %></p>
<% end %>
<% if flash[:error] %>
<% flash[:error].each do |e| %>
<p class="error message"><%= e + "." %></p>
<% end %>
<% end %>
<div class="form-column">
<label for="applicant[name]">Name*</label>
post '/applicants/new' do
updated_params = convert_datetime_params(params)
@applicant = Applicant.create(updated_params[:applicant])
if @applicant.save
flash[:notice] = "Successfully added new applicant."
redirect "/applicants/#{@applicant.id}"
else
flash[:error] = @applicant.errors.full_messages
flash[:errors_list] = @applicant.errors.messages
redirect "/applicants/new"
require './app/models/date_validator'
class Applicant < ActiveRecord::Base
include ActiveModel::Validations
validates_with DateValidator
validates :name, presence: true
validates :email, uniqueness: true, allow_nil: true
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :allow_nil => true
self.per_page = 10
after_validation :update_state
class DateValidator < ActiveModel::Validator
def validate(record)
future_date_validation(record)
date_sequence_validation(record)
end
private
def future_date_validation(record)
[:applied_on, :initial_reply_on, :completed_ttt_on, :reviewed_on, :resubmitted_ttt_on, :decision_made_on].each do |field|
module StateHelpers
# Current States
def get_applicants_by_state(current_state)
Applicant.where(:state => "#{current_state}").order("#{current_state} ASC")
end
# Time Lapse Helpers
def received_initial_reply
Applicant.all.select { |a| a.initial_reply_on != nil }
end
class Applicant < ActiveRecord::Base
validates :name, presence: true
validates :email, uniqueness: true, allow_nil: true
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create, :allow_nil => true
self.per_page = 10
after_validation :update_state
private
class Applicant < ActiveRecord::Base
validates :name, presence: true
validates :email, uniqueness: true, allow_nil: true
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create, :allow_nil => true
self.per_page = 10
after_validation :update_state
state_machine :initial => "applied_on" do
event :reply do