Auto create join table records through nested forms in rails3
So I have a model, lets call it posts.
Posts has many :tags
there is a tag join table called :tag_joins
Posts has many :tags, :through => :tag_joins
When I create a new tag, from the show view of a post, I'd like it automatically to create a record in the join table :tag_joins...
I feel like this should be possible by doing something like this in my post.rb file:
def tag_attributes=(hash)
hash.each do |tag_values|
tags << Tag.build
end
end开发者_高级运维
But its not working..Any ideas?
Update:
The error I'm receiving currently is in the PostsController in the update block:
unknown attribute: tag
I guess accepts_nested_attributes_for :tags, :tag_joins should do the job for you
精彩评论