I know my title was a tongue twister so I'll do my best to explain whats going on.
Firstly, I have a model. Lets call it posts.
Then I have a second model, which is essentially a join table, linking two different posts together. We can call that post connections.
I accomplished this by following the instructions here: Many-to-many relationship with the same model in rails? for Uni-directional, with additional fields.
The code for those models looks like:
class PostConnection < ActiveRecord::Base
belongs_to :post_a, :class_name => :Post
belongs_to :post_b, :class_name => :Post
end
class Post < ActiveRecord::Base
has_many(:post_connections, :foreign_key => :post_a_id, :dependent => :destroy)
has_many(:reverse_post_connections, :class_name => :PostConnection,
:foreign_key => :post_b_id, :dependent => :destroy)
has_many :posts, :through => :post_connections, :source => :post_b
accepts_nested_attributes_for :post_connections
end
This so far works fine - and when I create post connections manually using rails admin, they work just great.
The problem now, is I'd like to make a form which has post connections nested under posts.
I've been trying to follow the rails cast: http://railscasts.com/episodes/73-complex-forms-part-1
But even the first few steps didn't work. I didn't get an error. Nothing showed up where the fields were supposed to populate. (I'm wondering if it had to do with:
3.times { @post.post_connections.build }
)
Is there a more complicated way that I should be going about this based on the models?