wmoxam (owner)

Revisions

gist: 150908 Download_button fork
public
Public Clone URL: git://gist.github.com/150908.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# This is a straight up has_many :through 'tagging' model. No plugins.
 
>> t.update_attributes! :taggings_count => t.taggings.count
=> true
>> t.taggings_count
=> 9
>> t.reload
=> #<Tag id: 1, ...>
>> t.taggings_count
=> 0
 
>> # wtf?
 
>> # got it
>> Tag.update_counters(t.id, :taggings_count => t.taggings.count)
=> 1
>> t.reload
=> #<Tag id: 1, ...>
>> t.taggings_count
=> 9