Skip to content

Instantly share code, notes, and snippets.

## index.html.haml
[email protected] do |user|
-fetch_partial :short, :object => user # generated key should be "users/_short.html--object=#{user.to_param}"
## admins.html.haml
-fetch_fragment :count => User.admins.count do # key should be "path__to__admins__html__haml-1--count=#{User.admins.count}"
%ul
Merb::Router.prepare do
match("/hello") do
match("world").to(:controller => "worlds", :action => "hello") # matches /helloworld
match("there").to(:controller => "theres", :action => "hello") # matches /hellothere
end
default_routes
end
Fri Aug 15 15:25:39 -0500 2008: Read error: #<NoMethodError: undefined method `each' for nil:NilClass>
/opt/local/lib/ruby/gems/1.8/gems/merb-core-0.9.5/lib/merb-core/rack/handler/mongrel.rb:85:in `process'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/opt/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'
merb-cache was rewritten with a few goals in mind:
<ol>
<li>make it modulular</li>
<li>define a public <span class="caps">API</span></li>
<li>do the heavy lifting on key generation</li>
<li>100% thread-safe</li>
<li>work with multiple caching layers through the same <span class="caps">API</span></li>
<li>keep it hackable</li>
</ol>
# or, we can specify eager caching in the action itself
def index(page = 1)
unless page == 1
eager_cache :index do |controller|
controller.params[:page] = page + 1
end
end
display Acticle.paginate(:page => page)
end
merb-cache was rewritten with a few goals in mind:
# make it modulular
# define a public API
# do the heavy lifting on key generation
# 100% thread-safe
# work with multiple caching layers through the same API
# keep it hackable
h2. Stores
class CreditCard
include DataMapper::Resource
repository(:default) do
property :id, Serial
property :month, Integer
property :year, Integer
property :digits, Integer #last 5 digits
end
#models
class Cat < Mamal; end # loads the 'mamal.rb' if Mamal is undefined
#controller
Cats < Mamals; end # if mamals is a controller, is this kosher?
class Sessions < Application
def create
session.authenticate! #authenticates the user by username/password OR openid, raises an Unauthenticated if the user cannot be authenticated
redirect(url(:home))
end
end
class Session
def authenticate!
class Application < Merb::Controller
def _call_action(action)
repository(:default) { catch(:halt) { super(action) }}
end
end