Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- config.autoload_paths += %W(#{Rails.root}/app/workers
- #{Rails.root}/lib/validators
- #{Rails.root}/lib/content_items
- #{Rails.root}/lib/mongoid
- #{Rails.root}/lib/booher_modules
- )
- ## tree
- .
- ├── booher_modules
- │ └── voting_helpers.rb
- ├── campus_authorization.rb
- ├── configuration.rb
- ├── content_items
- │ ├── content_item.rb
- │ └── cover_picture.rb
- ├── development_mail_interceptor.rb
- ├── mongoid
- │ └── counter_cache.rb
- ├── paperclip_processors
- │ └── cropper.rb
- ├── special_characters.rb
- ├── string_extensions.rb
- ├── tasks
- │ ├── assets.thor
- │ ├── cba.rake
- │ ├── cucumber.rake
- │ ├── data.rake
- │ ├── delayed_jobs.rake
- │ ├── deploy.thor
- │ ├── set_data.rake
- │ └── test.thor
- ├── translator
- │ └── translator.rb
- └── validators
- └── email_validator.rb
- ## model
- class Vote
- include Mongoid::Document
- include Mongoid::Timestamps
- include Mongoid::CounterCache
- field :value, :type => Symbol # can be :aye, :nay, :abstain, :present
- counter_cache :name => 'polco_group', :field => 'vote_count'
- ## module
- module Mongoid
- module CounterCache
- extend ActiveSupport::Concern
- module ClassMethods
- def counter_cache(options)
- name = options[:name]
- counter_field = options[:field]
- after_create do |document|
- relation = document.send(name)
- relation.collection.update(relation._selector, {'$inc' => {counter_field.to_s => 1}})
- end
Add Comment
Please, Sign In to add comment