Skip to content

Instantly share code, notes, and snippets.

@cachafla
Forked from anonymous/gist:550339
Created August 25, 2010 21:40
Show Gist options
  • Save cachafla/550363 to your computer and use it in GitHub Desktop.
Save cachafla/550363 to your computer and use it in GitHub Desktop.
class Card
attr_accessor :new_employee_id
def reassign(employee_id)
old_card = self.card_assignments.all(:conditions=>["active_since < #{DateTime.now} and #{DateTime.now} < active_until"]).first
if !old_card.nil?
old_card.active_until = DateTime.now
old_card.save
end
active_card = CardAssignment.new(:card_id => self.id, :employee_id => employee_id)
active_card.active_since = DateTime.now
active_card.active_until = DateTime.now + 1.year
active_card.first_time = true
active_card.save
end
end
def update
@card = Card.find(params[:id])
if @card.update(params[:card])
@card.reassign(params[:card][:employee_id])
else
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment