$rails g migration add_votes_to_store
1
2
3
| def self.up
add_column :stores, :votes_count, :integer, :default => 0
end
|
1
2
3
4
5
| #model vote
class Vote < ActiveRecord::Base
belongs_to :store, :counter_cache => true
end
|
1
2
| #view
<%= store.votes_count %>
|