<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ruby on Rails Outsourcing &#187; rails</title>
	<atom:link href="http://www.ruby-on-rails-outsourcing.com/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ruby-on-rails-outsourcing.com</link>
	<description>Kirana Tama - Rails outsourcing company that helps small businesses minimize their costs</description>
	<lastBuildDate>Wed, 28 Jul 2010 05:58:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to create your own Rack Middleware class in Ruby on Rails</title>
		<link>http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/</link>
		<comments>http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/#comments</comments>
		<pubDate>Fri, 28 May 2010 10:52:14 +0000</pubDate>
		<dc:creator>William Notowidagdo</dc:creator>
				<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.ruby-on-rails-outsourcing.com/?p=256</guid>
		<description><![CDATA[We are going to demonstrate a simple Rack Middleware use in Rails.]]></description>
			<content:encoded><![CDATA[<p>We are going to demonstrate a simple <a href="http://rack.rubyforge.org/">Rack</a> Middleware use in Rails.<br />
<span id="more-256"></span><br />
<strong>What is Rack</strong><br />
Taken directly from its website,</p>
<blockquote><p>Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby.</p></blockquote>
<p>By wrapping HTTP requests and response, Rack standardized the interface for a web server to interact with a web application.</p>
<p><strong>Rack Middleware</strong><br />
Rails has been using Rack since version <a href="http://weblog.rubyonrails.org/2009/3/16/rails-2-3-templates-engines-rack-metal-much-more">2.3</a> and that gives Rails developers more power at their hands, such as enable Rack Middleware.</p>
<p>You might have heard about Rails Metal, which is similar to Middleware because it uses Rack interface to handle a request. The main difference is that Rails Metal acts as the endpoint of a request and returns a response while Middleware acts like a filter that can be used to intercept a request and alter the response.</p>
<p><strong>Creating the Middleware</strong><br />
To demonstrate Rack Middleware we are going to intercept any request for HTML pages so that we can first tidy up them.</p>
<p>We are going to use <a href="http://tidy.rubyforge.org/">tidy</a>, Ruby interface to HTML Tidy Library Project. You will need to install <a href="http://tidy.sourceforge.net/">HTML Tidy</a> for your distribution first before having the tidy gem installed. We are using tidy-1.0-126.1 on OpenSUSE 11.2 while writing this post.</p>
<p>The Middleware we are going to create is just a Ruby class. Create a file named <code>tidy_response.rb</code> inside the <code>lib</code> folder.</p>
<pre class="brush: rails">require 'tidy'

class TidyResponse
  def initialize(app)
    @app = app
  end

  def call(env)
    status, headers, response = @app.call(env)

    Tidy.path = '/usr/lib/libtidy-0.99.so.0'
    if headers["Content-Type"].include? "text/html"
      xml = Tidy.open do |tidy|
        tidy.options.output_xml = true
        xml = tidy.clean(response.body)
      end
    end

    [status, headers, xml]
  end
end</pre>
<p>Please note that you will need to replace the <code>Tidy.path</code> value according to your distribution.</p>
<p>Every Middleware classes have an initialize method that takes an application as an argument. As you notice we have created an instance variable called <code>@app</code> that will be a reference to Rails application.</p>
<pre class="brush: rails">def initialize(app)
  @app = app
end</pre>
<p>All Rack applications have a call method that takes an environment hash variable as an argument and returns an array containing an HTTP status, a hash of headers and a response object</p>
<pre class="brush: rails">status, headers, response = @app.call(env)</pre>
<p>In our example here, we first tidy up the response before return it to the client.</p>
<p><strong>Configuring the Middleware</strong><br />
We have to add a line in the <code>Rails::Initializer.run</code> block so the application knows to treat our new class as Middleware</p>
<pre class="brush: rails">Rails::Initializer.run do |config|
  config.middleware.use "TidyResponse"
...</pre>
<p>To test that our class is being use as a Middleware class we call rake middleware. Our <code>TidyResponse</code> should be list in the output</p>
<pre class="brush: rails">william@castafiore:/srv/www/htdocs/sandbox/testbed/rails&gt; rake middleware
(in /srv/www/htdocs/sandbox/testbed/rails)
use Rack::Lock
use ActionController::Failsafe
use ActionController::Session::CookieStore, #

use ActionController::ParamsParser
use Rack::MethodOverride
use Rack::Head
use ActionController::StringCoercion
use TidyResponse
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
run ActionController::Dispatcher.new</pre>
<p><strong>Testing the Middleware</strong><br />
To see whether the HTML is tidy up, we use untidy HTML in our view<br />
<script src="http://pastie.org/981582.js"></script> </p>
<p>so when you start the server without using the Middleware, this is what we get when viewing the source of the page </p>
<p><script src='http://pastie.org/981617.js'></script></p>
<p>Now start the server the view the source of the page using your browser and you should see<br />
<script src="http://pastie.org/981589.js"></script></p>
<p>The result is a much tidier HTML tags and smaller page size, also notice how HTML Tidy correcting the mismatched end tags<br />
<script src='http://pastie.org/981603.js'></script><br />
become</p>
<p><script src='http://pastie.org/981604.js'></script></p>
<p>Now you have written a working Middleware class. So enjoy your trip with Rack Middleware and feel free to comment your thoughts and questions!  </p>
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-sexy"><ul class="socials"><li class="sexy-delicious"><a href="http://del.icio.us/post?url=http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/&amp;title=How+to+create+your+own+Rack+Middleware+class+in+Ruby+on+Rails" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="sexy-digg"><a href="http://digg.com/submit?phase=2&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/&amp;title=How+to+create+your+own+Rack+Middleware+class+in+Ruby+on+Rails" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="sexy-stumbleupon"><a href="http://www.stumbleupon.com/submit?url=http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/&amp;title=How+to+create+your+own+Rack+Middleware+class+in+Ruby+on+Rails" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="sexy-technorati"><a href="http://technorati.com/faves?add=http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a></li><li class="sexy-facebook"><a href="http://www.facebook.com/share.php?u=http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/&amp;t=How+to+create+your+own+Rack+Middleware+class+in+Ruby+on+Rails" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="sexy-twitter"><a href="http://twitter.com/home?status=How+to+create+your+own+Rack+Middleware+class+in+Ruby+on+Rails+-+http://b2l.me/xgcgu+(via+@ptwgs)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="sexy-mail"><a href="mailto:?subject=%22How%20to%20create%20your%20own%20Rack%20Middleware%20class%20in%20Ruby%20on%20Rails%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22We%20are%20going%20to%20demonstrate%20a%20simple%20Rack%20Middleware%20use%20in%20Rails.%0D%0A%0D%0AWhat%20is%20Rack%0D%0ATaken%20directly%20from%20its%20website%2C%0D%0ARack%20provides%20a%20minimal%2C%20modular%20and%20adaptable%20interface%20for%20developing%20web%20applications%20in%20Ruby.%0D%0ABy%20wrapping%20HTTP%20requests%20and%20response%2C%20Rack%20standardized%20the%20interface%20for%20a%20web%20s%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="sexy-comfeed"><a href="http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="sexy-linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/&amp;title=How+to+create+your+own+Rack+Middleware+class+in+Ruby+on+Rails&amp;summary=We%20are%20going%20to%20demonstrate%20a%20simple%20Rack%20Middleware%20use%20in%20Rails.%0D%0A%0D%0AWhat%20is%20Rack%0D%0ATaken%20directly%20from%20its%20website%2C%0D%0ARack%20provides%20a%20minimal%2C%20modular%20and%20adaptable%20interface%20for%20developing%20web%20applications%20in%20Ruby.%0D%0ABy%20wrapping%20HTTP%20requests%20and%20response%2C%20Rack%20standardized%20the%20interface%20for%20a%20web%20s&amp;source=Ruby on Rails Outsourcing" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ruby-on-rails-outsourcing.com/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails best practices: Using named_scope</title>
		<link>http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/</link>
		<comments>http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 10:24:37 +0000</pubDate>
		<dc:creator>William Notowidagdo</dc:creator>
				<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.ruby-on-rails-outsourcing.com/?p=236</guid>
		<description><![CDATA[The named_scope method, which was introduced since Rails 2.1, allows us to do finds in a more elegant and comfortable than it was in use also make the code that we make more DRY.
By using named_scope we can apply certain conditions when we do find without having to write it repeatedly.
For example, say I have [...]]]></description>
			<content:encoded><![CDATA[<p>The <code>named_scope</code> method, which was introduced since Rails 2.1, allows us to do finds in a more elegant and comfortable than it was in use also make the code that we make more DRY.<span id="more-236"></span></p>
<p>By using <code>named_scope</code> we can apply certain conditions when we do find without having to write it repeatedly.</p>
<p>For example, say I have a <code>Book</code> model that has the attribute <code>published</code>. To get a list of books already published, by just using the find I can write it like this</p>
<pre class="brush: ruby">@books = Book.all(:conditions => ["published = ?", true])</pre>
<p>By way as above, I will probably write it again and again if I want to use the <code>@books</code> on different controllers. We can avoid this by adding <code>named_scope</code> on <code>Book</code> model such as the following</p>
<pre class="brush: ruby">class Book < ActiveRecord::Base
  named_scope :published_only, :conditions => ["published = ?", true]
end</pre>
<p>so I can use it in the controller simply by invoke</p>
<pre class="brush: ruby">@books = Book.published_only</pre>
<p>of the code snippet above we can see that by using <code>named_scope</code> we have added a class method with the name <code>published_only</code>.</p>
<p>Unlike <code>Book.find</code>, the object that is returned by <code>Book.published_only</code> is not an <code>Array</code> object but rather more like the association that was built by the <code>has_many</code> declaration. For example, we can invoke <code>Book.published_only.first</code> or <code>Book.published_only.count</code>. In addition we can also implementing <code>Enumerable</code> on the object that is returned by the <code>named_scope</code>, for example <code>Book.published_only.each(&#038;block)</code>.</p>
<p>Named Scopes can also be called in sequence, for example we have one more <code>named_scope</code></p>
<pre class="brush: ruby">named_scope :hard_cover_only, :conditions => ["cover = ?", "hard"]</pre>
<p>so that we can invoke</p>
<pre class="brush: ruby">Book.published_only.hard_cover_only</pre>
<p>Named Scopes are also available for <code>has_many</code> associations, eg</p>
<pre class="brush: ruby">class Author > ActiveRecord::Base
  has_many :books
end</pre>
<p>and</p>
<pre class="brush: ruby">rowling = Author.find(221)</pre>
<p>then <code>rowling.published_only.hard_cover_only</code> will return all books written by Rowling that have been published and has a hard cover.</p>
<p>You can also pass in variable by using a lambda</p>
<pre class="brush: ruby">class Book < ActiveRecord::Base
  named_scope :language, lambda { |language|
    { :conditions => { :language => language } }
  }
end</pre>
<p>then <code>Book.language('English')</code> will return a list of English books.</p>
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-sexy"><ul class="socials"><li class="sexy-delicious"><a href="http://del.icio.us/post?url=http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/&amp;title=Rails+best+practices%3A+Using+named_scope" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="sexy-digg"><a href="http://digg.com/submit?phase=2&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/&amp;title=Rails+best+practices%3A+Using+named_scope" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="sexy-stumbleupon"><a href="http://www.stumbleupon.com/submit?url=http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/&amp;title=Rails+best+practices%3A+Using+named_scope" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="sexy-technorati"><a href="http://technorati.com/faves?add=http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a></li><li class="sexy-facebook"><a href="http://www.facebook.com/share.php?u=http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/&amp;t=Rails+best+practices%3A+Using+named_scope" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="sexy-twitter"><a href="http://twitter.com/home?status=Rails+best+practices%3A+Using+named_scope+-+http://b2l.me/rhsp2+(via+@ptwgs)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="sexy-mail"><a href="mailto:?subject=%22Rails%20best%20practices%3A%20Using%20named_scope%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22The%20named_scope%20method%2C%20which%20was%20introduced%20since%20Rails%202.1%2C%20allows%20us%20to%20do%20finds%20in%20a%20more%20elegant%20and%20comfortable%20than%20it%20was%20in%20use%20also%20make%20the%20code%20that%20we%20make%20more%20DRY.%0D%0A%0D%0ABy%20using%20named_scope%20we%20can%20apply%20certain%20conditions%20when%20we%20do%20find%20without%20having%20to%20write%20it%20repeatedly.%0D%0A%0D%0AFor%20exa%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="sexy-comfeed"><a href="http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="sexy-linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/&amp;title=Rails+best+practices%3A+Using+named_scope&amp;summary=The%20named_scope%20method%2C%20which%20was%20introduced%20since%20Rails%202.1%2C%20allows%20us%20to%20do%20finds%20in%20a%20more%20elegant%20and%20comfortable%20than%20it%20was%20in%20use%20also%20make%20the%20code%20that%20we%20make%20more%20DRY.%0D%0A%0D%0ABy%20using%20named_scope%20we%20can%20apply%20certain%20conditions%20when%20we%20do%20find%20without%20having%20to%20write%20it%20repeatedly.%0D%0A%0D%0AFor%20exa&amp;source=Ruby on Rails Outsourcing" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ruby-on-rails-outsourcing.com/2010/04/27/rails-best-practices-using-named_scope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managing required gems in Rails project</title>
		<link>http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/</link>
		<comments>http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 08:36:10 +0000</pubDate>
		<dc:creator>William Notowidagdo</dc:creator>
				<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.ruby-on-rails-outsourcing.com/?p=227</guid>
		<description><![CDATA[While Rails itself already provides a lot of libraries that facilitate us to develop great web applications, but often we still need other Ruby libraries. Lucky for us because Ruby has rubygems that has become the standard format for library distribution. 
To tell Rails what are gems that required, we simply add code like this [...]]]></description>
			<content:encoded><![CDATA[<p>While <a href="http://www.rubyonrails.org">Rails</a> itself already provides a lot of libraries that facilitate us to develop great web applications, but often we still need other Ruby libraries. Lucky for us because Ruby has rubygems that has become the standard format for library distribution. <span id="more-227"></span></p>
<p>To tell Rails what are gems that required, we simply add code like this in <code>environment.rb</code></p>
<pre class="brush: ruby">config.gem "will_paginate"
config.gem "hpricot"
config.gem "fastercsv"</pre>
<p>Here are some ways to use gem in a Rails project.</p>
<p><strong>Install the gem in the system</strong></p>
<p>This way the most frequently used for those new to using Rails. Simply install the gem with the command: <code>gem install whateveryouneed</code> or <code>rake gems:install</code> and you are good to go. In this way requires us to ensure that gem is required have been installed on the server that is used for deployment later.</p>
<p>This method is quite practical when practiced by a small team or if you only as a developer, but would rather fuss if your team consists of many developers because they have to ensure that the required gem is already installed on their system.</p>
<p><strong>Freeze gems</strong></p>
<p>By using the command <code>rake gems: unpack</code>, all the gems that is required by your application will unpack into <code>vendor/gems</code> directory. Although this method will increase your application code size, but this will ease deployment later because gems do not have to be installed in the system.</p>
<p>Compared to the first method before, this method is more practical for a team that consists of many developers because each developer does not have to worry about whether the gem is needed is already installed on their system or not.</p>
<p><strong>Bundler</strong></p>
<p>This is the latest method. <a href="http://gembundler.com">Bundler</a> uses the management approach of the <a href="http://merbivore.com">Merb</a> and can be used not only on Rails course.</p>
<p>For Rails 2.3, Rails overriding Bundler own gem by inserting some handling code to <code>config/boot.rb</code> and create a new file <code>config/preinitializer.rb</code>. Then you move <code>config.gem</code> declarations to a file named Gemfile that is stored in the root directory of the application. We can categorize the required gem appropriate environment. Make sure to include Rails Itself and at least one source.</p>
<pre class="brush: ruby">source :gemcutter
gem "rails", "~&gt; 2.3.5"
gem "sqlite3-ruby", :require =&gt; "sqlite3"

# bundler requires these gems in all environments
# gem "nokogiri", "1.4.2"
# gem "geokit"

group :development do
  # bundler requires these gems in development
  # gem "rails-footnotes"
end

group :test do
  # bundler requires these gems while running tests
  # gem "rspec"
  # gem "faker"
end</pre>
<p>You should find more information on their website.</p>
<p>Just as open source itself, in the Rails world there are always some options in doing something, of course choices we make will be influenced by our own needs. So how about you? methods such as what you use in handling the required gem in Rails?</p>
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-sexy"><ul class="socials"><li class="sexy-delicious"><a href="http://del.icio.us/post?url=http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/&amp;title=Managing+required+gems+in+Rails+project" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="sexy-digg"><a href="http://digg.com/submit?phase=2&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/&amp;title=Managing+required+gems+in+Rails+project" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="sexy-stumbleupon"><a href="http://www.stumbleupon.com/submit?url=http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/&amp;title=Managing+required+gems+in+Rails+project" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="sexy-technorati"><a href="http://technorati.com/faves?add=http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a></li><li class="sexy-facebook"><a href="http://www.facebook.com/share.php?u=http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/&amp;t=Managing+required+gems+in+Rails+project" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="sexy-twitter"><a href="http://twitter.com/home?status=Managing+required+gems+in+Rails+project+-+http://b2l.me/pe6a9+(via+@ptwgs)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="sexy-mail"><a href="mailto:?subject=%22Managing%20required%20gems%20in%20Rails%20project%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22While%20Rails%20itself%20already%20provides%20a%20lot%20of%20libraries%20that%20facilitate%20us%20to%20develop%20great%20web%20applications%2C%20but%20often%20we%20still%20need%20other%20Ruby%20libraries.%20Lucky%20for%20us%20because%20Ruby%20has%20rubygems%20that%20has%20become%20the%20standard%20format%20for%20library%20distribution.%20%0D%0A%0D%0ATo%20tell%20Rails%20what%20are%20gems%20that%20require%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="sexy-comfeed"><a href="http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="sexy-linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/&amp;title=Managing+required+gems+in+Rails+project&amp;summary=While%20Rails%20itself%20already%20provides%20a%20lot%20of%20libraries%20that%20facilitate%20us%20to%20develop%20great%20web%20applications%2C%20but%20often%20we%20still%20need%20other%20Ruby%20libraries.%20Lucky%20for%20us%20because%20Ruby%20has%20rubygems%20that%20has%20become%20the%20standard%20format%20for%20library%20distribution.%20%0D%0A%0D%0ATo%20tell%20Rails%20what%20are%20gems%20that%20require&amp;source=Ruby on Rails Outsourcing" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ruby-on-rails-outsourcing.com/2010/04/14/managing-required-gems-in-rails-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using try method</title>
		<link>http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/</link>
		<comments>http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 04:17:59 +0000</pubDate>
		<dc:creator>William Notowidagdo</dc:creator>
				<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.ruby-on-rails-outsourcing.com/?p=220</guid>
		<description><![CDATA[Since Rails 2.3 released, a new try method was introduced. This new handy method allows you to invoke a method on a object without having to worry a NoMethodError exception will be raised. If the receiving object is a nil object then nil will be returned.
For example, there is no user with login &#8220;wolfman&#8221; so [...]]]></description>
			<content:encoded><![CDATA[<p>Since <a href="http://rubyonrails.org/">Rails</a> 2.3 released, a new <code>try</code> method was introduced. This new handy method allows you to invoke a method on a object without having to worry a <code>NoMethodError</code> exception will be raised. If the receiving object is a <code>nil</code> object then <code>nil</code> will be returned.</p>
<p>For example, there is no user with login &#8220;wolfman&#8221; so <code>user.email</code> will raise <code>NoMethodError</code></p>
<pre class="brush: ruby">
user = User.find_by_login("wolfman")
user.email
</pre>
<p>You can avoid <code>NoMethodError</code> using try</p>
<pre class="brush: ruby">
user = User.find_by_login("wolfman")
user.try(:email)
</pre>
<p>More documentation on <a href="http://api.rubyonrails.org/classes/Object.html#M000293">try</a>.</p>
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-sexy"><ul class="socials"><li class="sexy-delicious"><a href="http://del.icio.us/post?url=http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/&amp;title=Using+try+method" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="sexy-digg"><a href="http://digg.com/submit?phase=2&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/&amp;title=Using+try+method" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="sexy-stumbleupon"><a href="http://www.stumbleupon.com/submit?url=http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/&amp;title=Using+try+method" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="sexy-technorati"><a href="http://technorati.com/faves?add=http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a></li><li class="sexy-facebook"><a href="http://www.facebook.com/share.php?u=http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/&amp;t=Using+try+method" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="sexy-twitter"><a href="http://twitter.com/home?status=Using+try+method+-+http://b2l.me/hv2bk+(via+@ptwgs)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="sexy-mail"><a href="mailto:?subject=%22Using%20try%20method%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22Since%20Rails%202.3%20released%2C%20a%20new%20try%20method%20was%20introduced.%20This%20new%20handy%20method%20allows%20you%20to%20invoke%20a%20method%20on%20a%20object%20without%20having%20to%20worry%20a%20NoMethodError%20exception%20will%20be%20raised.%20If%20the%20receiving%20object%20is%20a%20nil%20object%20then%20nil%20will%20be%20returned.%0D%0A%20%0D%0AFor%20example%2C%20there%20is%20no%20user%20with%20login%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="sexy-comfeed"><a href="http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="sexy-linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/&amp;title=Using+try+method&amp;summary=Since%20Rails%202.3%20released%2C%20a%20new%20try%20method%20was%20introduced.%20This%20new%20handy%20method%20allows%20you%20to%20invoke%20a%20method%20on%20a%20object%20without%20having%20to%20worry%20a%20NoMethodError%20exception%20will%20be%20raised.%20If%20the%20receiving%20object%20is%20a%20nil%20object%20then%20nil%20will%20be%20returned.%0D%0A%20%0D%0AFor%20example%2C%20there%20is%20no%20user%20with%20login&amp;source=Ruby on Rails Outsourcing" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ruby-on-rails-outsourcing.com/2010/03/03/using-try-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails CMS</title>
		<link>http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/</link>
		<comments>http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 03:16:36 +0000</pubDate>
		<dc:creator>William Notowidagdo</dc:creator>
				<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[browsercms]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.ruby-on-rails-outsourcing.com/?p=202</guid>
		<description><![CDATA[Thanks to the guys that build BrowserCMS, our lives has just gotten easier!
No longer we have to stick with Radiant, BrowserCMS is, we think, easier and more robust.
This post is a simple getting started guide, that will help you to:

Install the BrowserCMS
Create a new page
Add text content to the newly created page
Publish your page


Installation
Packaged as [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to the guys that build <a href="http://www.browsercms.org/">BrowserCMS</a>, our lives has just gotten easier!<br />
No longer we have to stick with <a href="http://radiantcms.org/">Radiant</a>, BrowserCMS is, we think, easier and more robust.</p>
<p>This post is a simple getting started guide, that will help you to:</p>
<ol>
<li>Install the BrowserCMS</li>
<li>Create a new page</li>
<li>Add text content to the newly created page</li>
<li>Publish your page</li>
</ol>
<p><span id="more-202"></span></p>
<p><strong>Installation</strong></p>
<p>Packaged as a gem, you can include BrowserCMS in any <a href="http://www.rubyonrails.org/">Rails</a> (2.3 or later) project. Public assets, style sheets, images and JavaScript scripts is included in gem. In the installation process these assets will be copied to your project.</p>
<p>Let&#8217;s start install it by doing</p>
<pre class="brush: bash">
$ sudo gem install browsercms
</pre>
<p>By the time I wrote this post, the latest version was 3.0.6. Now create a project using a specific BrowserCMS template (a Rails template is simply a Ruby script with some domain-specific extensions to facilitate application configuration.)</p>
<pre class="brush: bash">
$ rails my_new_project_name -d mysql -m http://www.browsercms.org/templates/blank.rb
</pre>
<p>Unless you are not using password for your &#8216;root&#8217; account to connect to the database, you will see this error message</p>
<pre class="brush: bash">
Access denied for user 'root'@'localhost' (using password: NO)
</pre>
<p>you can reapply the template again at anytime after you change the database configuration in config/database.yml by running</p>
<pre class="brush: bash">
$ rake rails:template LOCATION=http://www.browsercms.org/templates/blank.rb
</pre>
<p>from your project directory. Now run the server</p>
<pre class="brush: bash">
$ script/server
</pre>
<p>and open your browser to <a href="http://localhost:3000/">http://localhost:3000/</a> and to log into the admin for the CMS go to <a href="http://localhost:3000/cms">http://localhost:3000/cms</a>. In development mode the default username/password is cmsadmin/cmsadmin. You should now be logged in.</p>
<p><strong>Create a new page</strong></p>
<p>On the home page, you will see a menu labeled &#8216;Home&#8217;, you want to create new page &#8216;About Us&#8217; with a menu link positioned below &#8216;Home&#8217;. Now log in into the CMS admin panel and do the following:</p>
<ol>
<li>Click on &#8216;SITEMAP&#8217;. The Sitemap page shows you a tree structure with all the sections and pages in your site, but you can add/edit pages/sections, and also can reorganize your pages/sections using drag and drop.</li>
<li>Click on &#8216;My Site&#8217;</li>
<li>Click on &#8216;Add Page&#8217;</li>
<li>On the displayed form, there are several fields to fill out. Name and template are the important ones</li>
<li>Click &#8216;SAVE&#8217; to create a new page</li>
</ol>
<p>You will be taken to the newly created page, which will be blank.</p>
<p><strong>Adding new text content to a page</strong></p>
<p>What you want to do now is to add some text content the your &#8216;About Us&#8217; page.</p>
<ol>
<li>Turn on the Visual Editor</li>
<li>Click on the &#8216;Add Content&#8217; icon below your page</li>
<li>Click on &#8216;Text&#8217; on the &#8216;Select Content Type&#8217; page</li>
<li>Fill out the &#8216;Name&#8217; and &#8216;Content&#8217; fields. You can enter &#8216;Tags&#8217; to your content as well</li>
<li>Click &#8216;SAVE&#8217;</li>
</ol>
<p><strong>Publish your page</strong></p>
<p>Your page is not published yet, to make it publicy available to the world click &#8216;PUBLISH&#8217;. To test your newly created page, simply log out from the admin panel and go to <a href="http://localhost:3000/about-us">http://localhost:3000/about-us</a>, you will see your text content you just added.</p>
<p>Hopefully this post will help you to getting started with BrowserCMS. Besides the concept that you need to understand, there are still many hidden power of BrowserCMS to be found and you can start from its <a href="http://www.browsercms.org/doc/guides/html/index.html">Reference Documentation</a>. </p>
<p>If you need help in developing a CMS solution in Ruby on Rails, please dont hesitate to contact us at <u>info[at]kiranatama[dot]com</u>!</p>
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-sexy"><ul class="socials"><li class="sexy-delicious"><a href="http://del.icio.us/post?url=http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/&amp;title=Rails+CMS" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="sexy-digg"><a href="http://digg.com/submit?phase=2&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/&amp;title=Rails+CMS" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="sexy-stumbleupon"><a href="http://www.stumbleupon.com/submit?url=http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/&amp;title=Rails+CMS" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="sexy-technorati"><a href="http://technorati.com/faves?add=http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a></li><li class="sexy-facebook"><a href="http://www.facebook.com/share.php?u=http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/&amp;t=Rails+CMS" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="sexy-twitter"><a href="http://twitter.com/home?status=Rails+CMS+-+http://b2l.me/dudb8+(via+@ptwgs)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="sexy-mail"><a href="mailto:?subject=%22Rails%20CMS%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22Thanks%20to%20the%20guys%20that%20build%20BrowserCMS%2C%20our%20lives%20has%20just%20gotten%20easier%21%0D%0ANo%20longer%20we%20have%20to%20stick%20with%20Radiant%2C%20BrowserCMS%20is%2C%20we%20think%2C%20easier%20and%20more%20robust.%0D%0A%0D%0AThis%20post%20is%20a%20simple%20getting%20started%20guide%2C%20that%20will%20help%20you%20to%3A%0D%0A%0D%0A%09Install%20the%20BrowserCMS%0D%0A%09Create%20a%20new%20page%0D%0A%09Add%20text%20cont%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="sexy-comfeed"><a href="http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="sexy-linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/&amp;title=Rails+CMS&amp;summary=Thanks%20to%20the%20guys%20that%20build%20BrowserCMS%2C%20our%20lives%20has%20just%20gotten%20easier%21%0D%0ANo%20longer%20we%20have%20to%20stick%20with%20Radiant%2C%20BrowserCMS%20is%2C%20we%20think%2C%20easier%20and%20more%20robust.%0D%0A%0D%0AThis%20post%20is%20a%20simple%20getting%20started%20guide%2C%20that%20will%20help%20you%20to%3A%0D%0A%0D%0A%09Install%20the%20BrowserCMS%0D%0A%09Create%20a%20new%20page%0D%0A%09Add%20text%20cont&amp;source=Ruby on Rails Outsourcing" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ruby-on-rails-outsourcing.com/2010/01/16/rails-cms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rails Multi-language</title>
		<link>http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/</link>
		<comments>http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 07:50:16 +0000</pubDate>
		<dc:creator>William Notowidagdo</dc:creator>
				<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.ruby-on-rails-outsourcing.com/?p=191</guid>
		<description><![CDATA[We have done multi-language feature for several Rails applications in the past, using gettext, gibberish, gibberish_db, etc. In this blog post I want to share the latest multi-language feature we built for our Netherland client recently, using Globalize2 plugin and Rails built-in I18n.
We used I18n for all our static contents, it&#8217;s a piece of cake. [...]]]></description>
			<content:encoded><![CDATA[<p>We have done <a href="http://www.google.com/search?q=rails+internationalization">multi-language feature for several Rails</a> applications in the past, using <a href="http://github.com/grosser/gettext_i18n_rails">gettext</a>, <a href="http://www.railslodge.com/plugins/345-gibberish">gibberish</a>, <a href="http://www.railslodge.com/plugins/912-gibberish-db">gibberish_db</a>, etc. In this blog post I want to share the latest multi-language feature we built for our Netherland client recently, using <a href="http://github.com/joshmh/globalize2">Globalize2</a> plugin and Rails built-in <a href="http://rails-i18n.org/">I18n</a>.</p>
<p>We used I18n for all our static contents, it&#8217;s a piece of cake. And all the client needs to do is to update that ymls files. For dynamic contents, we use Globalize2.</p>
<p>Here comes the fun part. Because you are most likely be working on an existing application, the bulk of the work is not making a nice back-end for multi-language objects, but it&#8217;s making sure the Rails application works correctly after we implement multi-language. It&#8217;s especially true when the application doesn&#8217;t have a complete test suite :)</p>
<p>Some things worth noting:</p>
<ol>
<li> All occurrences of find_by_name will no longer work correctly. So grep that and modify accordingly</li>
<li>Basically all queries that use &#8216;name&#8217; field, either on the select clause or condition clause, will also no longer work correctly</li>
<li>All routes that need locale path should also be added /locale/ to it</li>
<li>Javascript methods within a .js file that calls a Rails action and needs &#8216;locale&#8217;. Simply make a global Javascript variable for the locale and use that when necessary within the .js file</li>
<li>Javascript method that uses hard-coded words. Eg. &#8220;this.value = &#8216;Beware&#8217;&#8221;. Either we refactor it completely since it&#8217;s most likely we can do it another cleaner way, or we have to pull out that Javascript method from .js file to rhtml</li>
</ol>
<p>If you need a partner in developing your next Multi-language Rails application, we may be able to offer a good help! Contact us at <span style="text-decoration: underline;">info[at]kiranatama[dot]com</span></p>
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-sexy"><ul class="socials"><li class="sexy-delicious"><a href="http://del.icio.us/post?url=http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/&amp;title=Rails+Multi-language" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="sexy-digg"><a href="http://digg.com/submit?phase=2&amp;url=http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/&amp;title=Rails+Multi-language" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="sexy-stumbleupon"><a href="http://www.stumbleupon.com/submit?url=http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/&amp;title=Rails+Multi-language" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="sexy-technorati"><a href="http://technorati.com/faves?add=http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a></li><li class="sexy-facebook"><a href="http://www.facebook.com/share.php?u=http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/&amp;t=Rails+Multi-language" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="sexy-twitter"><a href="http://twitter.com/home?status=Rails+Multi-language+-+http://b2l.me/bhk4n+(via+@ptwgs)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="sexy-mail"><a href="mailto:?subject=%22Rails%20Multi-language%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22We%20have%20done%20multi-language%20feature%20for%20several%20Rails%20applications%20in%20the%20past%2C%20using%20gettext%2C%20gibberish%2C%20gibberish_db%2C%20etc.%20In%20this%20blog%20post%20I%20want%20to%20share%20the%20latest%20multi-language%20feature%20we%20built%20for%20our%20Netherland%20client%20recently%2C%20using%20Globalize2%20plugin%20and%20Rails%20built-in%20I18n.%0D%0A%0D%0AWe%20used%20I1%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="sexy-comfeed"><a href="http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="sexy-linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/&amp;title=Rails+Multi-language&amp;summary=We%20have%20done%20multi-language%20feature%20for%20several%20Rails%20applications%20in%20the%20past%2C%20using%20gettext%2C%20gibberish%2C%20gibberish_db%2C%20etc.%20In%20this%20blog%20post%20I%20want%20to%20share%20the%20latest%20multi-language%20feature%20we%20built%20for%20our%20Netherland%20client%20recently%2C%20using%20Globalize2%20plugin%20and%20Rails%20built-in%20I18n.%0D%0A%0D%0AWe%20used%20I1&amp;source=Ruby on Rails Outsourcing" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ruby-on-rails-outsourcing.com/2009/12/14/rails-multi-language/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PayPal Recurring Billing Ruby on Rails</title>
		<link>http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/</link>
		<comments>http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 04:51:52 +0000</pubDate>
		<dc:creator>William Notowidagdo</dc:creator>
				<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.ruby-on-rails-outsourcing.com/?p=179</guid>
		<description><![CDATA[About a month ago one of our development teams is fortunate enough to have the chance implementing ServiceMerchant plugin
It is a plugin that makes use of ActiveMerchant, but designed specifically for recurring billing / subscription payment requirement.
As with all other gems, the best way to understand a gem, besides asking shifu Google, is to dig [...]]]></description>
			<content:encoded><![CDATA[<p>About a month ago one of our development teams is fortunate enough to have the chance implementing <a href="http://servicemerchant.org/">ServiceMerchant</a> plugin<br />
It is a plugin that makes use of <a href="http://www.activemerchant.org/">ActiveMerchant</a>, but designed specifically for recurring billing / subscription payment requirement.</p>
<p>As with all other gems, the best way to understand a gem, besides asking shifu <a href="http://www.google.com">Google</a>, is to dig into the gem code itself and find sample apps, example usage, test units, etc</p>
<p>It&#8217;s pretty straightforward, and yet I feel like wanting to share some interesting things:</p>
<ol>
<li>If your <a href="http://www.paypal.com">PayPal</a> timezone is different from your server&#8217;s timezone, you have to take note. Otherwise PayPal might refuse user payment because the start subscription time is in the past!<br />
Assuming you are saving times in UTC in your database, the following code would work well as the start subscription date passed to PayPal:<br />
<code>TZInfo::Timezone.get(PAYPAL_TIMEZONE).utc_to_local(subscription.starts_on)</code></li>
<li>You want to keep a history of user activities (valid payments, invalid payments, cancellation, etc). In this case you&#8217;ll have to set a notification URL in your PayPal setting. Make sure the URL is accessible by Paypal, and check the example in ActiveMerchant:
<pre>/lib/active_merchant/billing/integrations/paypal/notification.rb</pre>
</li>
</ol>
<p>The necessary tweak is that we have to handle the case where a subscribing customer&#8217;s credit card on file has expired or becomes invalid &#8211; in which case we have to terminate the customer&#8217;s subscription on our database.</p>
<p>Btw if you need to develop a recurring billing paypal feature on your Rails app, we may be a good partner. Contact us <u>info[at]kiranatama[dot]com</u></p>
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-sexy"><ul class="socials"><li class="sexy-delicious"><a href="http://del.icio.us/post?url=http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/&amp;title=PayPal+Recurring+Billing+Ruby+on+Rails" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="sexy-digg"><a href="http://digg.com/submit?phase=2&amp;url=http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/&amp;title=PayPal+Recurring+Billing+Ruby+on+Rails" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="sexy-stumbleupon"><a href="http://www.stumbleupon.com/submit?url=http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/&amp;title=PayPal+Recurring+Billing+Ruby+on+Rails" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="sexy-technorati"><a href="http://technorati.com/faves?add=http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a></li><li class="sexy-facebook"><a href="http://www.facebook.com/share.php?u=http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/&amp;t=PayPal+Recurring+Billing+Ruby+on+Rails" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="sexy-twitter"><a href="http://twitter.com/home?status=PayPal+Recurring+Billing+Ruby+on+Rails+-+http://b2l.me/a3xyr+(via+@ptwgs)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="sexy-mail"><a href="mailto:?subject=%22PayPal%20Recurring%20Billing%20Ruby%20on%20Rails%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22About%20a%20month%20ago%20one%20of%20our%20development%20teams%20is%20fortunate%20enough%20to%20have%20the%20chance%20implementing%20ServiceMerchant%20plugin%0D%0AIt%20is%20a%20plugin%20that%20makes%20use%20of%20ActiveMerchant%2C%20but%20designed%20specifically%20for%20recurring%20billing%20%2F%20subscription%20payment%20requirement.%0D%0A%0D%0AAs%20with%20all%20other%20gems%2C%20the%20best%20way%20to%20u%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="sexy-comfeed"><a href="http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="sexy-linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/&amp;title=PayPal+Recurring+Billing+Ruby+on+Rails&amp;summary=About%20a%20month%20ago%20one%20of%20our%20development%20teams%20is%20fortunate%20enough%20to%20have%20the%20chance%20implementing%20ServiceMerchant%20plugin%0D%0AIt%20is%20a%20plugin%20that%20makes%20use%20of%20ActiveMerchant%2C%20but%20designed%20specifically%20for%20recurring%20billing%20%2F%20subscription%20payment%20requirement.%0D%0A%0D%0AAs%20with%20all%20other%20gems%2C%20the%20best%20way%20to%20u&amp;source=Ruby on Rails Outsourcing" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ruby-on-rails-outsourcing.com/2009/12/03/paypal-recurring-billing-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Bullet to detect n+1 queries problem</title>
		<link>http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/</link>
		<comments>http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 03:29:06 +0000</pubDate>
		<dc:creator>William Notowidagdo</dc:creator>
				<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.ruby-on-rails-outsourcing.com/?p=103</guid>
		<description><![CDATA[Probably you already know about n+1 queries problem, read this post if you want to learn how to detect those kind of queries.]]></description>
			<content:encoded><![CDATA[<p>Probably you already know about n+1 queries problem, read this post if you want to learn how to detect those kind of queries.<span id="more-103"></span></p>
<p>For example:</p>
<pre class="brush: rails">
class User &lt; ActiveRecord::Base
  has_many :items
end

class Item &lt; ActiveRecord::Base
  belongs_to :user
end
</pre>
<p>If we have 2 users, and several items we have controller like this:</p>
<pre class="brush: rails">
def index
  @users = User.find(:all)
end
</pre>
<p>and in the view we have something like this:</p>
<pre class="brush: rails">
&lt;% @users.each do |user| %&gt;
    &lt;%= user.items.collect(&amp;:name) %&gt;
&lt;% end %&gt;
</pre>
<p>If we watch the queries on the log, we should see something like this :</p>
<pre class="brush: sql">
SELECT * FROM "users"
SELECT * FROM "items" WHERE ("items".user_id = 1)
SELECT * FROM "items" WHERE ("items".user_id = 2)
</pre>
<p>if we have 1000 items, that means we are doing 1000+1 queries!<br />
Off course we can fix it like this (eager loading):</p>
<pre class="brush: rails">
def index
  @users = User.find(:all, :include =&gt; :items)
end
</pre>
<p>And now we only have two queries.</p>
<p>Detecting it in our application is another matter. If we have huge project, detecting it can be hard work and time wasting. I found a cool plugin/gem that help detecting n+1 queries problem, called <strong><a href="http://www.huangzhimin.com/projects/4-bullet">Bullet</a></strong>. You can install it as a gem:</p>
<pre class="brush: bash">
sudo gem install flyerhzm-bullet --source http://gems.github.com
</pre>
<p>or as a plugin</p>
<pre class="brush: bash">
script/plugin install git://github.com/flyerhzm/bullet.git
</pre>
<p>or you can build the gem right from the source from:</p>
<pre class="brush: bash">
git clone git://github.com/flyerhzm/bullet.git
cd bullet
gem build bullet.gemspec
sudo gem install bullet --local
</pre>
<p>If you are using it as a gem, don&#8217;t forget to include this in your environment.rb:</p>
<pre class="brush: rails">
config.gem 'flyerhzm-bullet', :lib =&gt; 'bullet', :source =&gt; 'http://gems.github.com'
</pre>
<p>include this in development.rb, and remember not to use bullet on production:</p>
<pre class="brush: bash">
config.after_initialize do
  Bullet.enable = true  
  Bullet::Association.alert = true
  Bullet::Association.bullet_logger = true
  Bullet::Association.rails_logger = false
end
</pre>
<p>You want to make two profiles in your Firefox, one for regular browsing, and one without caching enabled since sometimes it is not working in regular profile. So disable caching on your browser if you want to see pop-up box if we are doing n+1 queries. Also Bullet detect eager loading that is not used. I attached a screenshot so you can see it in action:</p>
<p style="text-align: center;"><img class=" aligncenter" title="Bullet in action" src="http://img697.imageshack.us/img697/471/snapshot3l.png" alt="Bullet in action" width="489" height="215" /></p>
</div>
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-bg-sexy"><ul class="socials"><li class="sexy-delicious"><a href="http://del.icio.us/post?url=http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/&amp;title=Using+Bullet+to+detect+n%2B1+queries+problem" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a></li><li class="sexy-digg"><a href="http://digg.com/submit?phase=2&amp;url=http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/&amp;title=Using+Bullet+to+detect+n%2B1+queries+problem" rel="nofollow" class="external" title="Digg this!">Digg this!</a></li><li class="sexy-stumbleupon"><a href="http://www.stumbleupon.com/submit?url=http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/&amp;title=Using+Bullet+to+detect+n%2B1+queries+problem" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a></li><li class="sexy-technorati"><a href="http://technorati.com/faves?add=http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a></li><li class="sexy-facebook"><a href="http://www.facebook.com/share.php?u=http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/&amp;t=Using+Bullet+to+detect+n%2B1+queries+problem" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a></li><li class="sexy-twitter"><a href="http://twitter.com/home?status=Using+Bullet+to+detect+n%2B1+queries+problem+-+http://b2l.me/ah3pd+(via+@ptwgs)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a></li><li class="sexy-mail"><a href="mailto:?subject=%22Using%20Bullet%20to%20detect%20n%2B1%20queries%20problem%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22Probably%20you%20already%20know%20about%20n%2B1%20queries%20problem%2C%20read%20this%20post%20if%20you%20want%20to%20learn%20how%20to%20detect%20those%20kind%20of%20queries.%0D%0A%0D%0AFor%20example%3A%0D%0A%0D%0Aclass%20User%20%26lt%3B%20ActiveRecord%3A%3ABase%0D%0A%20%20has_many%20%3Aitems%0D%0Aend%0D%0A%0D%0Aclass%20Item%20%26lt%3B%20ActiveRecord%3A%3ABase%0D%0A%20%20belongs_to%20%3Auser%0D%0Aend%0D%0A%0D%0AIf%20we%20have%202%20users%2C%20and%20severa%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a></li><li class="sexy-comfeed"><a href="http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a></li><li class="sexy-linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/&amp;title=Using+Bullet+to+detect+n%2B1+queries+problem&amp;summary=Probably%20you%20already%20know%20about%20n%2B1%20queries%20problem%2C%20read%20this%20post%20if%20you%20want%20to%20learn%20how%20to%20detect%20those%20kind%20of%20queries.%0D%0A%0D%0AFor%20example%3A%0D%0A%0D%0Aclass%20User%20%26lt%3B%20ActiveRecord%3A%3ABase%0D%0A%20%20has_many%20%3Aitems%0D%0Aend%0D%0A%0D%0Aclass%20Item%20%26lt%3B%20ActiveRecord%3A%3ABase%0D%0A%20%20belongs_to%20%3Auser%0D%0Aend%0D%0A%0D%0AIf%20we%20have%202%20users%2C%20and%20severa&amp;source=Ruby on Rails Outsourcing" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a></li></ul><div style="clear:both;"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ruby-on-rails-outsourcing.com/2009/11/18/using-bullet-to-detect-n1-queries-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
