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
## 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 |
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
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 |
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
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' |
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
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> | |
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
# 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 |
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
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 | |
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 CreditCard | |
include DataMapper::Resource | |
repository(:default) do | |
property :id, Serial | |
property :month, Integer | |
property :year, Integer | |
property :digits, Integer #last 5 digits | |
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
#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? |
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 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! |
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 Application < Merb::Controller | |
def _call_action(action) | |
repository(:default) { catch(:halt) { super(action) }} | |
end | |
end |