Created
June 14, 2012 18:18
-
-
Save davidjrice/2931928 to your computer and use it in GitHub Desktop.
This file contains 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 ApplicationController < ActionController::Base | |
before_filter :fetch_authors_and_categories | |
#... | |
private | |
def fetch_authors_and_categories | |
Couch.client(:bucket => 'system').pipelined do | |
@authors = Author.popular | |
@categories = Category.popular | |
end | |
end | |
#... | |
end |
This file contains 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
module Couch | |
class << self | |
def url | |
ENV['COUCHBASE_URL'] || "http://127.0.0.1:8091/pools/default" | |
end | |
def client(options = {}) | |
bucket = options.delete(:bucket) || "default" | |
@clients ||= {} | |
@clients[bucket] ||= Couchbase.new(url, :bucket => bucket) | |
end | |
end | |
end |
It should work right now with
@articles = []
Couch.client(:bucket => 'system').run do
Article.popular.fetch{|doc| @articles << doc}
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where
#load
is the same as#fetch
but yield whole collection at once