Created
June 9, 2010 14:03
-
-
Save RSpace/431510 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for(@production) do |form| %> | |
<%= form.label :title, 'Title' %> | |
<%= form.text_field :title %> | |
<%= form.fields_for :employee_roles do |role_form| %> | |
<%= form.label :employee_id %></dt> | |
<%= form.select :employee_id, ... %> | |
<%= form.label :role_id %></dt> | |
<%= form.select :role_id, ... %> | |
<% end %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Production < ActiveRecord::Base | |
has_many :employee_roles, :class_name => "ProductionEmployeeRole", :foreign_key => "production_id", :inverse_of => :production | |
accepts_nested_attributes_for :employee_roles, :allow_destroy => true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductionEmployeeRole < ActiveRecord::Base | |
belongs_to :production, :inverse_of => :employee_roles | |
belongs_to :employee, :inverse_of => :production_roles | |
belongs_to :role, :class_name => "ProductionRole", :foreign_key => "role_id", :inverse_of => :production_employee_roles | |
# The requirement of production_id results in the model not being valid when created together with a new production | |
validates_presence_of :role_id, :production_id, :employee_id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment