Skip to content

Instantly share code, notes, and snippets.

@pduersteler
Last active August 29, 2015 14:02
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 pduersteler/e4bdb20e5a5057d89dfe to your computer and use it in GitHub Desktop.
Save pduersteler/e4bdb20e5a5057d89dfe to your computer and use it in GitHub Desktop.
class EnrollmentController < ApplicationController
def new
@users_assignments = []
3.times{ @users_assignments << @event.assignments.build }
end
end
<%= semantic_form_for @event do |f| %>
<!--
Usually, there would be semantic_fields_for :jobs here,
but the user choses the job in a wishlist-form.
This leads to a
ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection error, saying
"Cannot modify association 'Event#assignments' because the source reflection class 'Assignment'
is associated to 'Job' via :has_many"
-->
<%= f.semantic_fields_for :assignments, @assignments do |a| %>
<%= a.input :job, as: :select, collection: @users_assignments %>
<% end %>
<% end %>
class Event < ActiveRecord::Base
has_many :jobs
has_many :assignments, through: :jobs
end
class Job < ActiveRecord::Base
belongs_to :event
has_many :assignments
end
class Assignment
belongs_to :job
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment