· 1 min read
Screencast: Bullet
Downloads in verschiedenen Formaten:
Resourcen:
terminal
[bash] rails g migration add_products_count_to_categories products_count:integer rails g migration cache_products_count rake db:migrate [/bash]
Gemfile
[ruby]
gem ‘bullet’, group: :development [/ruby]
config/initializers/bullet.rb
[ruby]
if defined? Bullet Bullet.enable = true # Bullet.alert = true Bullet.bullet_logger = true end [/ruby]
categories_controller.rb
[ruby]
def index @categories = Category.order(:name).includes(:products) end [/ruby]
db/migrate/cache_products_count.rb
[ruby]
class CacheProductsCount < ActiveRecord::Migration def up execute “update categories set products_count=(select count(*) from products where category_id=categories.id)” end
def down end end [/ruby]