Displaying 1 result from an estimated 1 matches for "category_id_as_str".
2006 Jan 04
2
Updating Attributes in a HABTM Join Table
...ategories_items" between them. If an item
is joined to a category once, no problem, we create the join. But if
an item is joined to a category more than once, I want to record the
subsequent hit in a field called "cat_count" which exists in the join
table.
def add_category( category_id_as_str )
category = Category.find(category_id_as_str.to_i)
if self.categories.include?(category)
old_count = self.categories.find(category.id).cat_count.to_i
self.categories.delete(category)
else
old_count = 0
end
self.categories.push_with_attributes(category, :cat_count =>
old_count + 1...