<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4182595251921988973</id><updated>2011-07-08T01:02:05.950-07:00</updated><category term='apt-get'/><category term='apt'/><category term='Lenny'/><category term='Plugin'/><category term='DDC'/><category term='Ruby'/><category term='Debian'/><category term='Database'/><category term='DynamicDatabaseChanger'/><category term='Rails'/><category term='Testing'/><title type='text'>./script/server webrick</title><subtitle type='html'>... mostly about Ruby and Rails...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://scriptserver.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://scriptserver.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>AlexP</name><uri>http://www.blogger.com/profile/03846491069208215127</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='22' height='32' src='http://1.bp.blogspot.com/_NOcF_sWvmII/STxOs9e7FtI/AAAAAAAAACY/F822KjCZZes/S220/0192_36095.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4182595251921988973.post-1465797813219697918</id><published>2009-09-01T06:40:00.001-07:00</published><updated>2009-09-02T01:02:26.644-07:00</updated><title type='text'>[ANN] Ruby Screencasts at www.RubyPulse.com</title><content type='html'>RubyPulse episode e0.5 - Gibbler was released!&lt;br /&gt;&lt;br /&gt;* &lt; &lt;a href="http://www.rubypulse.com/"&gt;http://www.rubypulse.com/&lt;/a&gt; &gt;&lt;br /&gt;&lt;br /&gt;Short screencasts about Ruby in alpha quality&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Episodes:&lt;br /&gt;&lt;br /&gt;## 0.1 2009-07-28 FastRI&lt;br /&gt;&lt;br /&gt;## 0.2 2009-08-03 memoize&lt;br /&gt;&lt;br /&gt;## 0.3 2009-08-24 gibbler&lt;br /&gt;&lt;br /&gt;## 0.4 2009-08-27 sketches&lt;br /&gt;&lt;br /&gt;## 0.5 2009-09-01 rvm&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Enjoy! - aaalex&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4182595251921988973-1465797813219697918?l=scriptserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptserver.blogspot.com/feeds/1465797813219697918/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4182595251921988973&amp;postID=1465797813219697918' title='43 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/1465797813219697918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/1465797813219697918'/><link rel='alternate' type='text/html' href='http://scriptserver.blogspot.com/2009/09/ann-ruby-screencasts-at-wwwrubypulsecom.html' title='[ANN] Ruby Screencasts at www.RubyPulse.com'/><author><name>AlexP</name><uri>http://www.blogger.com/profile/03846491069208215127</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='22' height='32' src='http://1.bp.blogspot.com/_NOcF_sWvmII/STxOs9e7FtI/AAAAAAAAACY/F822KjCZZes/S220/0192_36095.JPG'/></author><thr:total>43</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4182595251921988973.post-4508045015224012229</id><published>2009-06-25T01:33:00.000-07:00</published><updated>2009-06-25T02:22:02.719-07:00</updated><title type='text'>Howto use Sinatra in Rails Metal</title><content type='html'>just to let everybody know how easy it is to use Sinatra inside Rails 2.3:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;# use the Metal generator to generate&lt;br /&gt;./script/generate metal sinatra_test&lt;br /&gt;&lt;br /&gt;# add the sinatra gem as a dependency in envirenment.rb&lt;br /&gt;config.gem 'sinatra'&lt;br /&gt;&lt;br /&gt;# inside app/metal/sinatra_test.rb remove the SinatraTest class and use the following&lt;br /&gt;class SinatraTest &lt; Sinatra::Application&lt;br /&gt;  get '/test' do&lt;br /&gt;    content_type :text&lt;br /&gt;    status 200&lt;br /&gt;    "Hello World from Sinatra"&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;that's it... really easy&lt;br /&gt;&lt;br /&gt;and even better to just test the sinatra part, run:&lt;br /&gt;&lt;pre&gt;rackup app/metal/sinatra_test.rb&lt;/pre&gt;&lt;br /&gt;and access it with &lt;pre&gt;http://localhost:9292/test&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;-Alex&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4182595251921988973-4508045015224012229?l=scriptserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptserver.blogspot.com/feeds/4508045015224012229/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4182595251921988973&amp;postID=4508045015224012229' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/4508045015224012229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/4508045015224012229'/><link rel='alternate' type='text/html' href='http://scriptserver.blogspot.com/2009/06/howto-use-sinatra-in-rails-metal.html' title='Howto use Sinatra in Rails Metal'/><author><name>AlexP</name><uri>http://www.blogger.com/profile/03846491069208215127</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='22' height='32' src='http://1.bp.blogspot.com/_NOcF_sWvmII/STxOs9e7FtI/AAAAAAAAACY/F822KjCZZes/S220/0192_36095.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4182595251921988973.post-2827437551148424705</id><published>2009-06-24T00:46:00.000-07:00</published><updated>2009-06-24T01:22:57.438-07:00</updated><title type='text'>How do I tell Couch Potato to use http authentication?</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;During &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://it-republik.de/conferences/railswaycon/"&gt;RailswayCon&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;, I attended the session '&lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://www.slideshare.net/langalex/ruby-sittin-on-the-couch"&gt;Ruby sittin on the Couch&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;' by &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://twitter.com/langalex"&gt;Alexander Lang&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt; in which he mentioned &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://hosting.couch.io/"&gt;couch.io: Managed Hosting and Support for Apache CouchDB&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt; and also his GitHub project &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://github.com/langalex/couch_potato/"&gt;couch_potato&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;. And last weekend I decided to try that all out.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;After setting up the DB on couch.io, I managed to access it via &lt;a href="http://www.google.de/search?q=curl+manual"&gt;CURL&lt;/a&gt;, but it took me a long time and a hint by &lt;a href="http://twitter.com/langalex"&gt;Alexander Lang&lt;/a&gt; to figure out how to tell couch_potato to use BASIC AUTHENTICATION. Actually, you cannot use the default CouchPotato.database method. You have to create your own database instance with the underlying CouchRest:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;/code&gt;# define the CouchDB server through CouchRest&lt;br /&gt;CouchServer = CouchRest::Server.new "http://user:password@account.couch.io"&lt;br /&gt;&lt;br /&gt;# create the CouchRest database&lt;br /&gt;CouchRestDB = CouchRest::Database.new CouchServer, "database"&lt;br /&gt;&lt;br /&gt;# use that with CouchPotato&lt;br /&gt;CouchDB = CouchPotato::Database.new(CouchRestDB)&lt;code&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;-Alex&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;P.S. this also ended up on the &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://wiki.github.com/langalex/couch_potato"&gt;GitHub wiki page&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt; of &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://github.com/langalex/couch_potato/"&gt;couch_potato&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4182595251921988973-2827437551148424705?l=scriptserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptserver.blogspot.com/feeds/2827437551148424705/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4182595251921988973&amp;postID=2827437551148424705' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/2827437551148424705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/2827437551148424705'/><link rel='alternate' type='text/html' href='http://scriptserver.blogspot.com/2009/06/how-do-i-tell-couch-potato-to-use-http.html' title='How do I tell Couch Potato to use http authentication?'/><author><name>AlexP</name><uri>http://www.blogger.com/profile/03846491069208215127</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='22' height='32' src='http://1.bp.blogspot.com/_NOcF_sWvmII/STxOs9e7FtI/AAAAAAAAACY/F822KjCZZes/S220/0192_36095.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4182595251921988973.post-3983589108528041261</id><published>2007-08-30T08:02:00.000-07:00</published><updated>2007-08-30T08:58:26.377-07:00</updated><title type='text'>Quickie: find a route with ./script/console</title><content type='html'>... so I was playing around with hobo and wanted to add another method to a controller. The controller was made by hobo scaffolding and looked like that one:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class InstancesController &lt; ApplicationController&lt;br /&gt;  hobo_model_controller&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In hobo, you add another method by calling it a 'web_method':&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class InstancesController &lt; ApplicationController&lt;br /&gt;  hobo_model_controller&lt;br /&gt;  web_method :chart&lt;br /&gt;&lt;br /&gt;  def chart&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;According to the documentation, this should be all, but when I tried to use it:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ curl -v http://localhost:3000/instances/1/chart&lt;br /&gt;&gt; GET /instances/1/chart HTTP/1.1&lt;br /&gt;&gt; Host: localhost:3000&lt;br /&gt;&gt; Accept: */*&lt;br /&gt;&gt;&lt;br /&gt;&lt; HTTP/1.1 404 Not Found&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;and the server says:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Processing InstancesController#1 (for 127.0.0.1 at 2007-08-30 17:12:51) [GET]&lt;br /&gt;  Session ID: da18a6b4ef8b5d17773f4f4b3c117895&lt;br /&gt;  Parameters: {"action"=&gt;"1", "id"=&gt;"chart", "controller"=&gt;"instances"}&lt;br /&gt;&lt;br /&gt;Rendering /var/lib/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/templates/rescues/layout.rhtml (404 Page Not Found)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;wait a second... "action"=&gt;"1", "id"=&gt;"chart"... this should be the other way around! Hobo did not seem to have added the correct route. Let's have a look at that with the rails console:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ ./script/console&lt;br /&gt;Loading development environment.&lt;br /&gt;&gt;&gt; # List all routes&lt;br /&gt;?&gt; ActionController::Routing::Routes.named_routes.routes.each do |name, route|&lt;br /&gt;?&gt;  puts "%20s: %s" % [name, route] if name.to_s.include? "chart"&lt;br /&gt;&gt;&gt; end; nil&lt;br /&gt;      instance_chart: POST   /instances/:id/chart/ {:action=&gt; "chart", :controller=&gt;"instances"}&lt;br /&gt;=&gt; nil&lt;br /&gt;&gt;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Okay, here is the problem. The route is only added for POSTing it, not GETting :( So, let's use curl with a POST:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ curl -v -d "some_data" http://localhost:3000/instances/1/chart&lt;br /&gt;* Connected to localhost (127.0.0.1) port 3000 (#0)&lt;br /&gt;&gt; POST /instances/1/chart HTTP/1.1&lt;br /&gt;&gt; Host: localhost:3000&lt;br /&gt;&gt;&lt;br /&gt;&lt; HTTP/1.1 403 Forbidden&lt;br /&gt;&lt; Connection: close&lt;br /&gt;&lt; Date: Thu, 30 Aug 2007 15:26:59 GMT&lt;br /&gt;&lt; Set-Cookie: _supervisor_session_id=ee7182c092c5222820bf458316c19deb; path=/&lt;br /&gt;&lt; Status: 403 Forbidden&lt;br /&gt;&lt; Pragma: no-cache&lt;br /&gt;&lt; Cache-Control: no-store&lt;br /&gt;&lt; Server: Mongrel 1.0.1&lt;br /&gt;&lt; Content-Type: text/html; charset=utf-8&lt;br /&gt;&lt; Content-Length: 17&lt;br /&gt;&lt; Expires: 0&lt;br /&gt;&lt;&lt;br /&gt;* Closing connection #0&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Aha, a change. So, that's how hobo wants to do it. But I need to use GET. So, config/routes.rb needs an additinal route:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; map.named_route("instance_chart_get",&lt;br /&gt;                  "instances/:id/chart",&lt;br /&gt;                  :controller =&gt; 'instances',&lt;br /&gt;                  :action =&gt; 'chart',&lt;br /&gt;                  :conditions =&gt; { :method =&gt; :get } )&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And now, what does curl, now:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ curl -v http://localhost:3000/instances/1/chart&lt;br /&gt;* Connected to localhost (127.0.0.1) port 3000 (#0)&lt;br /&gt;&gt; POST /instances/1/chart HTTP/1.1&lt;br /&gt;&gt; Host: localhost:3000&lt;br /&gt;&gt;&lt;br /&gt;&lt; HTTP/1.1 403 Forbidden&lt;br /&gt;&lt; Connection: close&lt;br /&gt;&lt; Date: Thu, 30 Aug 2007 15:26:59 GMT&lt;br /&gt;&lt; Set-Cookie: _supervisor_session_id=ee7182c092c5222820bf458316c19deb; path=/&lt;br /&gt;&lt; Status: 403 Forbidden&lt;br /&gt;&lt; Pragma: no-cache&lt;br /&gt;&lt; Cache-Control: no-store&lt;br /&gt;&lt; Server: Mongrel 1.0.1&lt;br /&gt;&lt; Content-Type: text/html; charset=utf-8&lt;br /&gt;&lt; Content-Length: 17&lt;br /&gt;&lt; Expires: 0&lt;br /&gt;&lt;&lt;br /&gt;* Closing connection #0&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;and in the console:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ ./script/console&lt;br /&gt;Loading development environment.&lt;br /&gt;&gt;&gt; ActionController::Routing::Routes.named_routes.routes.each do |name, route|&lt;br /&gt;?&gt;  puts "%20s: %s" % [name, route] if name.to_s.include? "chart"&lt;br /&gt;&gt;&gt; end; nil&lt;br /&gt; instance_chart: POST /instances/:id/chart/ {:action=&gt;"chart", :controller=&gt;"instances"}&lt;br /&gt; instance_chart_get: GET /instances/:id/chart/ {:action=&gt;"chart", :controller=&gt;"instances"}&lt;br /&gt;=&gt; nil&lt;br /&gt;&gt;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt; Fine for me!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4182595251921988973-3983589108528041261?l=scriptserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptserver.blogspot.com/feeds/3983589108528041261/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4182595251921988973&amp;postID=3983589108528041261' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/3983589108528041261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/3983589108528041261'/><link rel='alternate' type='text/html' href='http://scriptserver.blogspot.com/2007/08/quickie-find-route-with-scriptconsole.html' title='Quickie: find a route with ./script/console'/><author><name>AlexP</name><uri>http://www.blogger.com/profile/03846491069208215127</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='22' height='32' src='http://1.bp.blogspot.com/_NOcF_sWvmII/STxOs9e7FtI/AAAAAAAAACY/F822KjCZZes/S220/0192_36095.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4182595251921988973.post-2596361608484182083</id><published>2007-06-20T02:15:00.000-07:00</published><updated>2007-06-26T06:03:06.166-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='Rails'/><title type='text'>Quickie: using alias_method_chain</title><content type='html'>... while doing some development on my ddcplugin, I had to use the feature alias_method_chain to extend some of ActionController's functionality, but I wasn't able to find a good description on the net on how to use that. So, here is a quicky about that.&lt;br /&gt;&lt;br /&gt;You have:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class MyClass&lt;br /&gt; def aMethod&lt;br /&gt;  puts "Hi"&lt;br /&gt; end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;you want to add a feature to aMethod&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class MyClass&lt;br /&gt; def aMethod_with_feature&lt;br /&gt;  puts "feature"&lt;br /&gt;  aMethod_without_feature&lt;br /&gt; end&lt;br /&gt; alias_method_chain :aMethod, :feature&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Ok, simply put, you have to name the new method 'aMethod_with_feature'. If you want to call the old method, you use 'aMethod_without_feature'. The rest is done by alias_method_chain and your new functionality will be in. Remember that you have to specify the names of the methods as symbols. *thumbs_up*&lt;br /&gt;&lt;br /&gt;-alex&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://errtheblog.com/post/1109" class="reverse url" rel="bookmark"&gt;“alias_method_bling&lt;/a&gt;&lt;a href="http://errtheblog.com/post/1109"&gt;”&lt;/a&gt;&lt;br /&gt;&lt;a href="http://weblog.rubyonrails.org/2006/4/26/new-in-rails-module-alias_method_chain"&gt;New in Rails: Module#alias_method_chain&lt;/a&gt;&lt;br /&gt;&lt;a href="http://blog.teksol.info/articles/2007/06/06/interesting-technique-using-alias_method_chain"&gt;Interesting technique using #alias_method_chain&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4182595251921988973-2596361608484182083?l=scriptserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptserver.blogspot.com/feeds/2596361608484182083/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4182595251921988973&amp;postID=2596361608484182083' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/2596361608484182083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/2596361608484182083'/><link rel='alternate' type='text/html' href='http://scriptserver.blogspot.com/2007/06/quicky-using-aliasmethodchain.html' title='Quickie: using alias_method_chain'/><author><name>AlexP</name><uri>http://www.blogger.com/profile/03846491069208215127</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='22' height='32' src='http://1.bp.blogspot.com/_NOcF_sWvmII/STxOs9e7FtI/AAAAAAAAACY/F822KjCZZes/S220/0192_36095.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4182595251921988973.post-6798719948271320776</id><published>2007-06-15T07:57:00.000-07:00</published><updated>2007-06-17T23:49:36.472-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DynamicDatabaseChanger'/><category scheme='http://www.blogger.com/atom/ns#' term='Plugin'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='DDC'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><category scheme='http://www.blogger.com/atom/ns#' term='Rails'/><title type='text'>Rails Database Loadbalancing with DynamicDatabaseChanger Example</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;Okay, as requested by DrNic, I will give a quick example on how to loadbalance a &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://www.rubyonrails.org/"&gt;Rails&lt;/a&gt; application to a clustered database with my &lt;a style="font-family: trebuchet ms;" href="http://rubyforge.org/projects/ddcplugin/"&gt;DynamicDatabaseChanger&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt; plugin.&lt;br /&gt;&lt;br /&gt;The assumptions for this to work is that you can connect to whatever database server you want to for reading &lt;span style="font-weight: bold;"&gt;and&lt;/span&gt; for writing. All instances have the same database.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;... and of course you should have installed the plugin from svn://rubyforge.org/var/svn/ddcplugin&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;So, here we go. First, we need to define all the additional DB instances that we could connect to in database.yml:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;shared: &amp;shared&lt;br /&gt; adapter: mysql&lt;br /&gt; encoding: utf8&lt;br /&gt; username: rails&lt;br /&gt; password: rails_password&lt;br /&gt; database: app_production&lt;br /&gt;&lt;br /&gt;production:&lt;br /&gt; &lt;&lt;: *shared&lt;br /&gt; host: db&lt;br /&gt;production0:&lt;br /&gt; &lt;&lt;: *shared&lt;br /&gt; host: db1&lt;br /&gt;production1:&lt;br /&gt; &lt;&lt;: *shared&lt;br /&gt; host: db2&lt;br /&gt;production2:&lt;br /&gt; &lt;&lt;: *shared&lt;br /&gt; host: db3&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;As you can see, the standard production DB is located on host db, the additional ones on db[1-3]. The rest of the definitions is the same for all.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;Next, we have to tell the plugin when to use what DB. We do this in environment.rb:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;ActionController::Base.dynamic_database_change_guard=&lt;br /&gt;Proc.new{ |request|&lt;br /&gt; prodDBs = ActiveRecord::Base.configurations.keys.select&lt;br /&gt;                         {|k| k.include? "production" }&lt;br /&gt; prodDBs[rand(prodDBs.size)]&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Wh&lt;/span&gt;at happens here? This is the central decision point of the plugin. The implementation here simply fetches all affected DB definitions from database.yml and returns a random one.&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;br /&gt;That's all! It's just that simple.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;What happens in the background? The plugin adds an around filter to the beginning of the ActionController processing. In this hook, the above function is called and depending on the result, the connection of ActiveRecord::Base is changed. From then on, the action is processed using the changed database connection. After finishing the request, the connection is reseted to the standard one.&lt;br /&gt;&lt;br /&gt;I implemented this in my lab at home( the hard part was the database set up ;-) and it worked quite well.&lt;br /&gt;&lt;br /&gt;More examples can be found in the &lt;a href="http://viewvc.rubyforge.mmmultiworks.com/cgi/viewvc.cgi/trunk/README?revision=2&amp;root=ddcplugin&amp;amp;view=markup"&gt;README&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;So, try it out for your self and tell me your results.&lt;br /&gt;&lt;br /&gt;-alex&lt;br /&gt;&lt;br /&gt;P.S. instead of using 4 different DB servers for testing this, it's possible to use 1 DB server with 4 different users and see in the DB log the different users connecting:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;pre&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;shared: &amp;amp;shared&lt;br /&gt; adapter: mysql&lt;br /&gt; encoding: utf8&lt;br /&gt; database: app_production&lt;br /&gt; host: db&lt;br /&gt;&lt;br /&gt;production:&lt;br /&gt; &lt;&lt;: *shared&lt;br /&gt; username: rails&lt;br /&gt; password: rails_password&lt;br /&gt;production0:&lt;br /&gt; &lt;&lt;: *shared&lt;br /&gt; username: rails1&lt;br /&gt; password: rails1_password&lt;br /&gt;production1:&lt;br /&gt; &lt;&lt;: *shared&lt;br /&gt; username: rails2&lt;br /&gt; password: rails2_password&lt;br /&gt;production2:&lt;br /&gt; &lt;&lt;: *shared&lt;br /&gt; username: rails3&lt;br /&gt; password: rails3_password&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4182595251921988973-6798719948271320776?l=scriptserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptserver.blogspot.com/feeds/6798719948271320776/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4182595251921988973&amp;postID=6798719948271320776' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/6798719948271320776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/6798719948271320776'/><link rel='alternate' type='text/html' href='http://scriptserver.blogspot.com/2007/06/rails-database-loadbalancing-with.html' title='Rails Database Loadbalancing with DynamicDatabaseChanger Example'/><author><name>AlexP</name><uri>http://www.blogger.com/profile/03846491069208215127</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='22' height='32' src='http://1.bp.blogspot.com/_NOcF_sWvmII/STxOs9e7FtI/AAAAAAAAACY/F822KjCZZes/S220/0192_36095.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4182595251921988973.post-5255161953931459896</id><published>2007-06-15T03:43:00.000-07:00</published><updated>2007-06-15T04:25:11.882-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Testing'/><category scheme='http://www.blogger.com/atom/ns#' term='apt'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='apt-get'/><category scheme='http://www.blogger.com/atom/ns#' term='Lenny'/><category scheme='http://www.blogger.com/atom/ns#' term='Debian'/><category scheme='http://www.blogger.com/atom/ns#' term='Rails'/><title type='text'>Quickie: Installing Ruby and Rubygems on Debian Testing</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;So, I &lt;/span&gt;use Debian Lenny (Testing) for all my Ruby and Rails stuff, but I haven't found a good tutorial on how to get this running without stepping into some traps. So, here is my way:&lt;br /&gt;&lt;br /&gt;- get a clean install of &lt;a href="http://www.debian.org/"&gt;Debian&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;apt-get update&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;apt-get &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;-y &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;upgrade&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- install &lt;a href="http://ruby-lang.org/"&gt;Ruby&lt;/a&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;apt-get &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;-y &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;install ruby1.8 irb1.8 rdoc1.8 ri1.8 ruby1.8-dev&lt;br /&gt;apt-get &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;-y &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;install libzlib-ruby1.8&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; libopenssl-ruby1.8&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- install &lt;a href="http://www.rubygems.org/"&gt;Rubygems&lt;/a&gt; via apt-get&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;apt-get -y install rubygems&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- the 'gem' command should work, now. (Note that the Rubygems .deb package is Version 0.9.4 !!!)&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&gt; gem env&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;RubyGems Environment:&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;VERSION: 0.9.4 (0.9.4)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;INSTALLATION DIRECTORY: /var/lib/gems/1.8&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;GEM PATH:&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;     - /var/lib/gems/1.8&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;REMOTE SOURCES:&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic;"&gt;     - http://gems.rubyforge.org&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;&lt;/span&gt;&lt;span style="font-style: italic;"&gt;-&lt;/span&gt; add the gems/bin dir to your $PATH by adding this to &lt;span style="font-weight: bold;"&gt;~/.bashrc&lt;/span&gt;:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;export PATH=$PATH:`gem env gemdir`/bin&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;that's all :-)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Notes:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;'gem update --system' will not notice the different gems dir under Debian. So, all gems will disappear after that. Be aware!!!&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style=";font-family:trebuchet ms;font-size:100%;"  &gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4182595251921988973-5255161953931459896?l=scriptserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptserver.blogspot.com/feeds/5255161953931459896/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4182595251921988973&amp;postID=5255161953931459896' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/5255161953931459896'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/5255161953931459896'/><link rel='alternate' type='text/html' href='http://scriptserver.blogspot.com/2007/06/quickie-installing-ruby-and-rubygems-on.html' title='Quickie: Installing Ruby and Rubygems on Debian Testing'/><author><name>AlexP</name><uri>http://www.blogger.com/profile/03846491069208215127</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='22' height='32' src='http://1.bp.blogspot.com/_NOcF_sWvmII/STxOs9e7FtI/AAAAAAAAACY/F822KjCZZes/S220/0192_36095.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4182595251921988973.post-407354785390816506</id><published>2007-06-14T07:26:00.000-07:00</published><updated>2007-06-17T23:31:46.412-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DynamicDatabaseChanger'/><category scheme='http://www.blogger.com/atom/ns#' term='Plugin'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='DDC'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><category scheme='http://www.blogger.com/atom/ns#' term='Rails'/><title type='text'>Uploaded the DynamicDatabaseChanger Plugin to RubyForge</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;Yesterday, I moved the first attempt of my &lt;/span&gt;&lt;a href="http://rubyforge.org/projects/ddcplugin/"&gt;&lt;span style="font-family:trebuchet ms;"&gt;DynamicDatabaseChanger&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt; Plugin for &lt;/span&gt;&lt;a href="http://rubyonrails.org/"&gt;&lt;span style="font-family:trebuchet ms;"&gt;RoR&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt; onto &lt;/span&gt;&lt;a href="http://rubyforge.org/"&gt;&lt;span style="font-family:trebuchet ms;"&gt;RubyForge&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;. It can be viewed at&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://rubyforge.org/projects/ddcplugin/"&gt;&lt;span style="font-family:trebuchet ms;"&gt;http://rubyforge.org/projects/ddcplugin/&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;br /&gt;&lt;br /&gt;and the sources can be installed with: svn checkout &lt;em&gt;svn://rubyforge.org/var/svn/ddcplugin/trunk&lt;/em&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;This plugin can be used to change the database connection of the RoR application dynamically for each request.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=";font-family:trebuchet ms;font-size:130%;"  &gt;&lt;strong&gt;What is this good for?&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;2 real world usage come to my mind at the moment( and have been tested)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;- RubyOnRails database loadbalancing&lt;/span&gt; ( similar to &lt;a href="http://drnicwilliams.com/2007/04/12/magic-multi-connections-a-facility-in-rails-to-talk-to-more-than-one-database-at-a-time/"&gt;Dr. Nic's Magic Multi-Connections: A “facility in Rails to talk to more than one database at a time”&lt;/a&gt; or &lt;a href="http://revolutiononrails.blogspot.com/2007/04/plugin-release-actsasreadonlyable.html"&gt;ActsAsReadonlyable&lt;/a&gt; from Revolution On Rails)&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;- using a different database for a set of IPs&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;In my next posts I will show you how to use the plugin and give examples for the cases above...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;I hope that somebody will find it to be useful and give me some feedback.&lt;br /&gt;&lt;br /&gt;-Alex&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4182595251921988973-407354785390816506?l=scriptserver.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://scriptserver.blogspot.com/feeds/407354785390816506/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4182595251921988973&amp;postID=407354785390816506' title='1 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/407354785390816506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4182595251921988973/posts/default/407354785390816506'/><link rel='alternate' type='text/html' href='http://scriptserver.blogspot.com/2007/06/uploaded-dynamicdatabasechanger-plugin.html' title='Uploaded the DynamicDatabaseChanger Plugin to RubyForge'/><author><name>AlexP</name><uri>http://www.blogger.com/profile/03846491069208215127</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='22' height='32' src='http://1.bp.blogspot.com/_NOcF_sWvmII/STxOs9e7FtI/AAAAAAAAACY/F822KjCZZes/S220/0192_36095.JPG'/></author><thr:total>1</thr:total></entry></feed>
