Last active
August 29, 2015 14:02
-
-
Save pduersteler/e4bdb20e5a5057d89dfe 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
class EnrollmentController < ApplicationController | |
def new | |
@users_assignments = [] | |
3.times{ @users_assignments << @event.assignments.build } | |
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
<%= 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 %> |
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 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