Thank you Pokkai Dokkai for your reply, i have 3 questions:
1) I am using has_many :through association because i want the
association to be open for more fields in case i need it to.
2) I am already setting up the an empty array in the blogs controller
(in the update and the new action) before it runs the tagging method,
isn't that supposed to work or is it that rails will automatically
take care of it?
params[:blog][:tagging] ||= [] #This is how i'm setting the empty
array in case that none of the checkboxes was selected.
3) What is the difference between the has_many :through association
with the primary key and without it?
On Oct 5, 11:57 pm, Pokkai Dokkai <[EMAIL PROTECTED]>
wrote:
> RoR_Nb wrote:
> > def tagging=(tagging)
> > tags.each do |tag|
> > tag.destroy unless tagging.include? (tag.blog_id.to_i)
> > end
> > tagging.each do |tag|
> > self.tags.create(:technology_id => tag) unless tags.any?{|t|
> > t.technology_id.to_i == tag.to_i}
> > end
> > end
>
> > ....
>
> try to use has_and_belongs_to_many association if your intermediate
> table has only two columns (foreign_keys)
>
> if you want to delete associated record directly then assign
> @blog.tags=[]
> it will aiotumatically delete those records
> don't use
> tag.destroy
>
> otherwise use has_many :through association with a primary key (remove
> :id=>false)
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---