Skip to content

Instantly share code, notes, and snippets.

Created August 26, 2010 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/551502 to your computer and use it in GitHub Desktop.
Save anonymous/551502 to your computer and use it in GitHub Desktop.
#EN LA VISTA
<% active_assignment = @card.active_assignment %>
<% @card.old_employee_id = active_assignment.employee_id if !active_assignment.nil? %>
<%= f.select("new_employee_id", @employees.collect{|e| [ e.name + " " + e.last_name, e.id ] }, {:include_blank => true, :selected => @card.old_employee_id}) %>
...
#EN EL CONTROLADOR
if @card.update_attributes(params[:card])
if params[:card][:new_employee_id] != params[:card][: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
...
attr_accessor :old_employee_id
...
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