Merb core pobrany z repozytorium Git’a
Merb-Core Git
cd merb-core
rake install
sudo gem install pkg/merb-core-0.9.0.gem
[code=ruby]require ‘rubygems’
require ‘merb-core’
Merb::Router.prepare do |r|
r.default_routes
end
class Foo < Merb::Controller
Returning a string is the easiest.
def index
sleep 20
“Hello from the index action”
end
You could also render a string manually through Erubis.
def show
template_object = Erubis::Eruby.new(<<-EOL)
Hello, world
Here are the params: <%= params.inspect %>
EOL
render template_object.result(binding)
end
end
Merb.start :environment => ‘production’,
:adapter => ‘mongrel’,
:framework => {},
:log_level => ‘debug’,
:use_mutex => false,
:session_store => ‘none’,
:session_secret_key => ‘5b7d26c4d99b922929b7c30ce06be0fd58a71500’,
:exception_details => true,
:reload_classes => true,
:reload_time => 0.5[/code]
cd sample/merb-very-flat
Upewniasz się, że masz nowego Merba:
[code]merb -v
-> merb 0.9.0 (dev)[/code]
Jeśli masz 0.5.0 to odinstaluj: gem uninstall merb i zainstaluj na nowo merb-core.
Teraz:
merb -I merb-very-flat.rb
W FF otwierasz 2 taby:
http://localhost:4000/foo/index
http://localhost:4000/foo/show
Zauważ, że akcja show zwraca odpowiedź niezależnie od akcji index, która blokuje:
Thu, 14 Feb 2008 11:13:33 GMT ~ Not Using Sessions
Thu, 14 Feb 2008 11:16:18 GMT ~ Params: {}
Thu, 14 Feb 2008 11:16:18 GMT ~ Cookies: {}
Thu, 14 Feb 2008 11:16:18 GMT ~ Routed to: {:controller=>"foo", :action=>"index", :format=>nil, :id=>nil}
Thu, 14 Feb 2008 11:16:22 GMT ~ Params: {}
Thu, 14 Feb 2008 11:16:22 GMT ~ Cookies: {}
Thu, 14 Feb 2008 11:16:22 GMT ~ Routed to: {:controller=>"foo", :action=>"show", :format=>nil, :id=>nil}
Thu, 14 Feb 2008 11:16:22 GMT ~ {:before_filters_time=>1.4e-05, :after_filters_time=>1.4e-05, :action_time=>0.001276}
Thu, 14 Feb 2008 11:16:38 GMT ~ {:before_filters_time=>1.5e-05, :after_filters_time=>2.5e-05, :action_time=>20.001198}