Skip to content

Instantly share code, notes, and snippets.

@RSpace
Created June 9, 2010 14:03
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 RSpace/431510 to your computer and use it in GitHub Desktop.
Save RSpace/431510 to your computer and use it in GitHub Desktop.
<%= 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 %>
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
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