Skip to content

Instantly share code, notes, and snippets.

@cachafla
Forked from anonymous/gist:551502
Created August 26, 2010 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cachafla/551529 to your computer and use it in GitHub Desktop.
Save cachafla/551529 to your computer and use it in GitHub Desktop.
#EN LA VISTA
<%= hidden_field_tag(:old_employee_id, @old_employee_id) %>
<%= f.select("new_employee_id", @employees.collect{|e| [ e.name + " " + e.last_name, e.id ] }, {:include_blank => true, :selected => @old_employee_id}) %>
...
#EN EL CONTROLADOR
# en edit
@card = Card.find(params[:id])
...
...
active_assignment = @card.active_assignment
@old_employee_id = active_assignment.employee_id if !active_assignment.nil?
# en update
if @card.update_attributes(params[:card])
if params[:card][:new_employee_id] != params[:old_employee_id]
@card.reassign(params[:card][:new_employee_id])
end
format.html { redirect_to(@card, :notice => 'Card was successfully updated.') }
format.xml { head :ok }
else
...
#NUEVAS COSAS EN EL MODELO
class Card < ActiveRecord::Base
def active_assignment()
self.card_assignments.all(:conditions=>["active_since < '#{DateTime.now.utc}' and '#{DateTime.now.utc}' < active_until"]).first
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment