This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| QUEUE=high,normal,low rake resque:work |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Resque.redis = Redis::Namespace.new(:resque, :redis => $redis) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/controller/posts_controller.rb | |
| class PostsController < ApplicationController | |
| before_filter :find_post | |
| protected | |
| def find_post | |
| if id = Slug[params[:id]] | |
| @post = Post.find(id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Post.find_each { |post| Slug[post.id.to_s] = post.id.to_s } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/models/post.rb | |
| class Post < ActiveRecord::Base | |
| validate :ensure_slug_uniqueness | |
| protected | |
| # validate | |
| def ensure_slug_uniqueness | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PostObserver | |
| def after_save(post) | |
| Slug[post.slug] = post.id | |
| return true | |
| end | |
| def after_destroy(post) | |
| Slug.destroy(post.id) | |
| return true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Slug | |
| class << self | |
| def [](slug) | |
| redis.hget(hash, slug) | |
| end | |
| def []=(slug, id) | |
| if old = self[slug] | |
| redis.srem(set(old), slug) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Slug | |
| class << self | |
| def [](slug) | |
| redis.hget(hash, slug) | |
| end | |
| def []=(slug, id) | |
| if old = self[slug] | |
| redis.srem(set(old), slug) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Slug | |
| class << self | |
| def [](slug) | |
| redis.hget(hash, slug) | |
| end | |
| def []=(slug, id) | |
| redis.hset(hash, slug, id) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PostObserver | |
| def after_save(post) | |
| Slug[post.slug] = post.id.to_s | |
| return true | |
| end | |
| end |