I'm using ryan bates' plugin nested_form and i have been trying to write my form for a has_many :through relationship.
I have 3 models:
Profile
has_many :memberships
has_many :organizations, :through => :memberships
accepts_attributes_for :organizations
attr_accessible :organization_attribtues
Membership
has_many :profiles
has_many :organizations
Organization
has_many :memberships
has_many :profiles, :though => :memberships
The below form is for the profile but with the organization nested inside of it. I can create information about the organization by doing f.fields_for :organizations, but then I'm unclear on how to update information specific to their membership in the organization. Specifically, there is a title attribute on the membership table ( i commented it out below because it throws an error undefined method `title' for Organisation). Any help would be so very appreciated! Thanks.
= f.fields_for :organisations do |org|
= org.input :name, :label => "<strong>Name of the Organization</strong>"
= org.input :title, :label => "Your role"
= org.input :description, :as => :text, :label => "Description of the organization",
As I saw here on StackOverflow with another question, I need to nest the hm => t like so
BUt with Ryan Bates' plugin, the association to memberships organisations is not built as far as i can tell, so i created a new method like this:
And then I pretty much just copied Ryan Bates' plugin verbatim adding a new parameter adding 2 lines below
Look for the references to "association_two". This works great!