<?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>Kolodvor &#187; Ruby</title>
	<atom:link href="http://www.kolodvor.net/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kolodvor.net</link>
	<description>ruby, rails, javascript, jquery, ...</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:24:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Divisible</title>
		<link>http://www.kolodvor.net/2011/03/26/divisible/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=divisible</link>
		<comments>http://www.kolodvor.net/2011/03/26/divisible/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 07:59:01 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.kolodvor.net/?p=283</guid>
		<description><![CDATA[I just published my first ruby gem on rubygems.org. It is a simple gem that is useful in case you need to find out if one number is divisible by another. Usage 9.divisible_by(3) # => true 10.divisible_by(3) # => false &#8230; <a href="http://www.kolodvor.net/2011/03/26/divisible/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just published <a href="https://rubygems.org/gems/divisible">my first ruby gem</a> on <a href="https://rubygems.org/">rubygems.org</a>. It is a simple gem that is useful in case you need to find out if one number is divisible by another.</p>
<h3>Usage</h3>
<pre class="code">
  9.divisible_by(3) # => true
  10.divisible_by(3) # => false
  12.divisible_by(3) # => true
  12.divisible_by(4) # => true
  15.divisible_by(4) # => false
</pre>
<p>Same can be done with</p>
<pre class="code">
  Divisible.check(9, 3) # => true
  Divisible.check(10, 3) # => false
  Divisible.check(12, 3) # => true
  Divisible.check(12, 4) # => true
  Divisible.check(15, 4) # => false
</pre>
<h3>Installation</h3>
<pre class="code">
  gem install divisible
</pre>
<p>For more info go to <a href="https://github.com/vlado/divisible">https://github.com/vlado/divisible</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2011/03/26/divisible/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Number of workdays between two dates</title>
		<link>http://www.kolodvor.net/2010/08/01/number-of-workdays-between-two-dates/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=number-of-workdays-between-two-dates</link>
		<comments>http://www.kolodvor.net/2010/08/01/number-of-workdays-between-two-dates/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 21:55:34 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.kolodvor.net/?p=274</guid>
		<description><![CDATA[It is pretty simple to get number of work days between two dates. For example we can get the number of workdays in this month. start_date = Date.civil(2010, 8, 1) end_date = Date.civil(2010, 8, 31) workdays = (start_date..end_date).select { &#124;day&#124; &#8230; <a href="http://www.kolodvor.net/2010/08/01/number-of-workdays-between-two-dates/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It is pretty simple to get number of work days between two dates. For example we can get the number of workdays in this month.</p>
<pre class="code">
  start_date = Date.civil(2010, 8, 1)
  end_date = Date.civil(2010, 8, 31)
  workdays = (start_date..end_date).select { |day| ![0, 6].include?(day.wday) }.size
</pre>
<p><span id="more-274"></span></p>
<p>Please note that this doesn&#8217;t include any check for holidays, you&#8217;ll need to figure that yourself (if you have need for that at all). </p>
<p>For more info see <a href="http://ruby-doc.org/ruby-1.9/classes/Array.html#M000724">Array#select</a> and <a href="http://ruby-doc.org/ruby-1.9/classes/Date.html#M001468">Date#wday</a> methods.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/08/01/number-of-workdays-between-two-dates/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple Search Rails plugin</title>
		<link>http://www.kolodvor.net/2010/06/26/simple-search-rails-plugin/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simple-search-rails-plugin</link>
		<comments>http://www.kolodvor.net/2010/06/26/simple-search-rails-plugin/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 08:31:11 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[simple]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=234</guid>
		<description><![CDATA[SimpleSearch brings simple search to ActiveRecord. It ads simple_search named scope that accepts query as parameter. The idea is that you provide the query and plugin does the rest (splits query to keywords and compose where statement). This can be &#8230; <a href="http://www.kolodvor.net/2010/06/26/simple-search-rails-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>SimpleSearch brings simple search to ActiveRecord. It ads <span class="code">simple_search</span> named scope that accepts query as parameter.</p>
<p>The idea is that you provide the query and plugin does the rest (splits query to keywords and compose where statement).</p>
<p>This can be very useful in case you just want to filter list of records by some query, you have autocomplete field, &#8230; or something similar.</p>
<p><span id="more-234"></span></p>
<h3>Example</h3>
<p><strong>View</strong></p>
<pre class="code">
  &lt;% form_tag request.path, :method => 'get' do %>
    &lt;%= text_field_tag :query, params[:query] %>
  &lt;% end %>
</pre>
<p><strong>Model</strong></p>
<pre class="code">
  class User < ActiveRecord::Base
    acts_as_simply_searchable
  end

  # Columns: id, login, email, crypted_password, salt
</pre>
<p><strong>Controller</strong></p>
<pre class="code">
  class UsersController < ApplicationController
    def index
      @users = User.simple_search(params[:query]).all
    end
  end
</pre>
<p><strong>Query examples</strong></p>
<p>Simple query</p>
<pre class="code">
  User.simple_search("vlado")
  # => SELECT * FROM "users" WHERE (users.id LIKE '%vlado%' OR users.login LIKE '%vlado%' OR users.email LIKE '%vlado%' OR users.crypted_password LIKE '%vlado%' OR users.salt LIKE '%vlado%')
</pre>
<p>You can also provide <span class="code">:columns => :column1, :column2, ...</span> option to limit search only to those columns</p>
<pre class="code">
  class User < ActiveRecord::Base
    acts_as_simply_searchable :columns => :login, :email
  end
</pre>
<p></p>
<pre class="code">
  User.simple_search("vlado")
  # => SELECT * FROM "users" WHERE (users.login LIKE '%vlado%' OR users.email LIKE '%vlado%')
</pre>
<p>More complex query</p>
<pre class="code">
  User.simple_search("vlado, cingel")
  # will search for users matching 'vlado' and 'cingel' keywords
  # => SELECT * FROM "users" WHERE ((users.login LIKE '%vlado%' OR users.email LIKE '%vlado%') AND (users.login LIKE '%cingel%' OR users.email LIKE '%cingel%'))
</pre>
<p><strong>NOTE: With proper use of indexes this plugin can work quite well in most cases, but in case you have a large and complex database it is usually much better idea to use some search daemon like <a href="http://freelancing-god.github.com/ts/en/">Thinking Sphinx</a>.</strong></p>
<h3>More info</h3>
<p><a href="http://github.com/cingel/simple_search">http://github.com/cingel/simple_search</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/06/26/simple-search-rails-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby library for parsing, validating and formatting phone numbers</title>
		<link>http://www.kolodvor.net/2010/01/04/ruby-library-for-parsing-validating-and-formatting-phone-numbers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ruby-library-for-parsing-validating-and-formatting-phone-numbers</link>
		<comments>http://www.kolodvor.net/2010/01/04/ruby-library-for-parsing-validating-and-formatting-phone-numbers/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 16:19:39 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[phone numbers]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=107</guid>
		<description><![CDATA[Tomislav Car has just released Phone, Ruby library for phone number parsing, validation and formatting. It should save you a lot of time if you need any of the following: * you have area where users input phone numbers in &#8230; <a href="http://www.kolodvor.net/2010/01/04/ruby-library-for-parsing-validating-and-formatting-phone-numbers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/carr">Tomislav Car</a> has just released <a href="http://github.com/carr/phone">Phone</a>, Ruby library for phone number parsing, validation and formatting. It should save you a lot of time if you need any of the following:</p>
<p>* you have area where users input phone numbers in many different formats<br />
* output phone numbers in specific format<br />
* you need to send SMS messages from your app<br />
* &#8230;</p>
<p><span id="more-107"></span></p>
<p>You can initialize new Phone object with <code>Phone.new</code></p>
<pre class="code">
  Phone.new('5125486', '91', '385')
</pre>
<p>or</p>
<pre class="code">
  Phone.new(:number => '5125486', :area_code => '91', :country_code => '385')
</pre>
<p>Parsing is done using <code>Phone.parse</code> method</p>
<pre class="code">
    Phone.parse '091/512-5486', :country_code => '385'
    Phone.parse '(091) 512 5486', :country_code => '385'
</pre>
<p>It is smart to set default contry code first so you don&#8217;t have to provide it as option every time</p>
<pre class="code">
    Phone.default_country_code = '385'
    Phone.parse '091/512-5486'
    Phone.parse '(091) 512 5486'
</pre>
<p><span style="text-decoration:line-through">Fow now, Phone works only for Croatian, Slovenian, Bosnian and Serbian phone numbers, but Tomislav is collecting data to support other countries.</span></p>
<p><a href="http://github.com/carr/phone">Go check it out</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2010/01/04/ruby-library-for-parsing-validating-and-formatting-phone-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Radiant CMS, disable caching in development</title>
		<link>http://www.kolodvor.net/2009/09/19/radiant-cms-disable-caching-in-development/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=radiant-cms-disable-caching-in-development</link>
		<comments>http://www.kolodvor.net/2009/09/19/radiant-cms-disable-caching-in-development/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 20:14:19 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://kolodvor.net/?p=51</guid>
		<description><![CDATA[I am working on extension for Radiant CMS. I wanted to disable caching for development, but wasn&#8217;t able to find right method for this, so finally I did it by putting this into my extensions activate method if RAILS_ENV=="development" Page.class_eval &#8230; <a href="http://www.kolodvor.net/2009/09/19/radiant-cms-disable-caching-in-development/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am working on extension for <a href="http://radiantcms.org">Radiant CMS</a>. I wanted to disable caching for development, but wasn&#8217;t able to find right method for this, so finally I did it by putting this into my extensions activate method</p>
<pre class="code">
if RAILS_ENV=="development"
  Page.class_eval {
    def cache?
      false
    end
  }
end
</pre>
<p>This is more of a hack then a real solution, so please use comments to point me in the right direction. I&#8217;m using Radiant version 0.8.1.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2009/09/19/radiant-cms-disable-caching-in-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determining the number of days in a month</title>
		<link>http://www.kolodvor.net/2007/08/22/determining-the-number-of-days-in-a-month/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=determining-the-number-of-days-in-a-month</link>
		<comments>http://www.kolodvor.net/2007/08/22/determining-the-number-of-days-in-a-month/#comments</comments>
		<pubDate>Wed, 22 Aug 2007 10:18:20 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://nbabc.org/wordpress/?p=6</guid>
		<description><![CDATA[Here is a simple method that returns number of days for wanted month and year. If year is ommited current year is selected. def month_days(month, year=Date.today.year) mdays = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, &#8230; <a href="http://www.kolodvor.net/2007/08/22/determining-the-number-of-days-in-a-month/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is a simple method that returns number of days for wanted month and year. If year is ommited current year is selected.</p>
<pre class="code">def month_days(month, year=Date.today.year)
  mdays = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  mdays[2] = 29 if Date.leap?(year)mdays[month]
end
</pre>
<p>Simple examples:</p>
<pre class="code">
month_days(1)       =&gt; 31
month_days(2, 2007) =&gt; 28
month_days(2, 2008) =&gt; 29
</pre>
<p>Now, let&#8217;s assume we have a date from a database, and we want to find number of days in a month from that date.</p>
<pre class="code">
month_days(date.month, date.year)
</pre>
<p>But with two more lines of code</p>
<p><span id="more-8"></span></p>
<pre class="code">
def month_days(date_or_month, year=Date.today.year)
  year = date_or_month.year if date_or_month.class == Date
  month = date_or_month.class == Date ? date_or_month.month : date_or_month

  mdays = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  mdays[2] = 29 if Date.leap?(year)
  mdays[month]
end</pre>
<p>we could find it like this:</p>
<pre class="code">
month_days(date)</pre>
<p>It is worth mentioning that if String is passed as an argument</p>
<pre class="code">
month_days("2007-02-15")</pre>
<p>we will get an ERROR, because first argument must be a Fixnum or a Date.</p>
<pre class="code">
month_days("2007-02-15".to_date)</pre>
<p>If you want to use this as a helper in Rails, create the file <span class="code">date_helper.rb</span> in a lib directory of your app, and put this in:</p>
<pre class="code">
module ActionView
  module Helpers
    module DateHelper

      def month_days(date_or_month, year=Date.today.year)
        year = date_or_month.year if date_or_month.class == Date
        month = date_or_month.class == Date ? date_or_month.month : date_or_month

        mdays = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        mdays[2] = 29 if Date.leap?(year)
        mdays[month]
      end

    end
  end
end
</pre>
<p>and then add this line to <span class="code">config/environment.rb</span></p>
<pre class="code">
require lib/date_helper.rb
</pre>
<p><!-- technorati tags start -->
<p style="text-align:right;font-size:10px;">Technorati Tags: <a href="http://www.technorati.com/tag/month days" rel="tag">month days</a>, <a href="http://www.technorati.com/tag/ruby" rel="tag">ruby</a></p>
<p><!-- technorati tags end --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2007/08/22/determining-the-number-of-days-in-a-month/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Inject</title>
		<link>http://www.kolodvor.net/2007/08/03/ruby-inject/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ruby-inject</link>
		<comments>http://www.kolodvor.net/2007/08/03/ruby-inject/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 21:19:33 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://nbabc.org/wordpress/?p=5</guid>
		<description><![CDATA[You probably frequently have to iterate through a list and accumulate a result that changes as you iterate. Let&#8217;s take the following array: nums = [1, 3, 5, 7] If you want to find a sum of all the items &#8230; <a href="http://www.kolodvor.net/2007/08/03/ruby-inject/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You probably frequently have to iterate through a list and accumulate a result that changes as you iterate. Let&#8217;s take the following array: </p>
<pre class="code">
nums = [1, 3, 5, 7]
</pre>
<p>If you want to find a sum of all the items in the array, you could write something like this:</p>
<pre class="code">
sum = 0
nums.each { |n| sum += n }
</pre>
<p>This works fine, but it doesn&#8217;t look much elegant. Luckly, for us that wants to be elegant there is a inject method.<br />
(See: <a href="http://www.ruby-doc.org/core/classes/Enumerable.html#M003171">Enumerable::inject</a>)</p>
<pre class="code">
sum = nums.inject(0) { |x,n| x+n }
</pre>
<p>This code does the same thing, but also looks cool. Inject acomplish this by using accumulator or accumulated value (x). At each step accumulated value is set to the value returned by the block. Here, we set accumulator initial value to 0, and at each step current value from array (n) is added to accumulated value.  </p>
<p>If initial value is omitted, the first item is used as the accumulator initial value and is then omitted from iteration.</p>
<pre class="code">
sum = nums.inject { |x,n| x+n }
</pre>
<p>Is same as</p>
<pre class="code">
sum = nums[0]
nums[1..-1].each { |n| sum += n }
</pre>
<p>Another example.<br />
We have array with five names:</p>
<pre class="code">
names = ["michael", "ron", "scottie", "dennis", "toni"]
</pre>
<p>The following code:</p>
<pre class="code">
string = names.inject("") { |x,n| x << "#{n} " }
</pre>
<p>Will output:</p>
<pre>
=> "michael ron scottie dennis toni "
</pre>
<p>You can get the same output with:</p>
<pre class="code">
string = ""
names.each { |n| string << "#{n} "}
</pre>
<p>Now, let's say you won't to separate them with comma, and capitalize those that have more then four characters.<br />
You can do it like this:</p>
<pre class="code">
string = ""
names.each do |n|
  name = n.length > 4 ? n.capitalize : n
  n == names.last ? string << name : string << "#{name}, "
end
</pre>
<p>Or like this:</p>
<pre class="code">
string = names.inject("") do |x,n|
  name = n.length > 4 ? n.capitalize : n
  n == names.last ? x << name : x << "#{name}, "
end
</pre>
<p>In both ways we get the same result:</p>
<pre>
=> "Michael, ron, Scottie, Dennis, toni"
</pre>
<p><!-- technorati tags start -->
<p style="text-align:right;font-size:10px;">Technorati Tags: <a href="http://www.technorati.com/tag/array" rel="tag">array</a>, <a href="http://www.technorati.com/tag/enumerable" rel="tag">enumerable</a>, <a href="http://www.technorati.com/tag/inject" rel="tag">inject</a>, <a href="http://www.technorati.com/tag/ruby" rel="tag">ruby</a></p>
<p><!-- technorati tags end --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2007/08/03/ruby-inject/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Quick Start with Rails on OS X</title>
		<link>http://www.kolodvor.net/2007/07/25/quick-start-with-rails-on-os-x/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=quick-start-with-rails-on-os-x</link>
		<comments>http://www.kolodvor.net/2007/07/25/quick-start-with-rails-on-os-x/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 09:28:07 +0000</pubDate>
		<dc:creator>vlado</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://nbabc.org/wordpress/?p=3</guid>
		<description><![CDATA[Install Ruby OS X (10.4) comes with Ruby 1.8.2 already installed. For a quick start this is OK so let&#8217;s install Rails. Install Rails Since Rails comes as gem package, first we need to install RubyGems. Download the latest package &#8230; <a href="http://www.kolodvor.net/2007/07/25/quick-start-with-rails-on-os-x/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>Install Ruby</h3>
<p>OS X (10.4) comes with Ruby 1.8.2 already installed.<br />
For a quick start this is OK so let&#8217;s install Rails.</p>
<h3>Install Rails</h3>
<p>Since Rails comes as gem package, first we need to install <a href="http://www.rubygems.org/">RubyGems</a>.<br />
Download the latest package from <a href="http://rubyforge.org/frs/?group_id=126">RubyForge</a> and unzip it.<br />
Now go to the directory where you unpacked the package and run</p>
<pre>$ sudo ruby setup.rb</pre>
<p>When asked enter your password, and after install finish you can verify that everything went well by typing:</p>
<pre>$ gem -v</pre>
<p>Output should look something like this, depending on version you installed</p>
<pre>=> 0.9.4</pre>
<p>Now installing Rails is as simple as</p>
<pre>$ sudo gem install rails --include-dependencies</pre>
<p>To verify installation, type: </p>
<pre>$ rails -v
=> Rails 1.2.3</pre>
<h3>Install MySQL</h3>
<p>You can skip this step if you don&#8217;t want to use database but since Rails is a framework for developing database-backed web applications, you&#8217;ll probably want to use <a href="http://wiki.rubyonrails.org/rails/pages/DatabaseDrivers">one</a>.</p>
<ol>
<li>Download the <a href="http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg">MySQL package for OS X</a> for your platform</li>
<li>Double-click the drive image to mount it</li>
<li>Locate the MySQL installer (something like mysql-5.0.45-osx10.4-i686.pkg) and run it, authenticating as needed</li>
<li>Double-click MySQLStartupItem.pkg</li>
<li>Double-click MySQL.prefPane and install it</li>
</ol>
<p>Once the install is complete, start the MySQL server using the control panel. ( System Preferences -> Other -> MySQL ) and check Automatically Start MySQL Server on Startup</p>
<h3>Test your installation</h3>
<p>To start a new project (application), go to the directory where you plan to keep your applications (i.e. ~/Apps) and execute following commands</p>
<pre>
$ rails test_app
$ cd test_app
$ ./script/server
</pre>
<p>This will generate Rails skeleton in ~/Apps/test_app, and start a WEBrick server on port 3000.<br />
Now open your browser and enter http://localhost:3000 in address bar. You should see a page with &#8220;Welcome aboard, You&#8217;re riding the Rails!&#8221; message.</p>
<p>We also need to tell Rails which database to use.<br />
To do this edit database.yml file (~/Apps/test_app/config/database.yml) to look like this</p>
<pre>
development:
  adapter: mysql
  database: test_app_development
  username: root
  password:
  host: localhost

test:
  adapter: mysql
  database: test_app_test
  username: root
  password:
  host: localhost

production:
  adapter: mysql
  database: test_app_production
  username: root
  password:
  host: localhost
</pre>
<p>Naturally we also need to create a database</p>
<pre>
$ mysqladmin -u root create test_app_development
</pre>
<p>and table in that database</p>
<pre>
$ mysql -u root

mysql> create table items (
         id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
         name VARCHAR(100) );
</pre>
<p>Execute scaffold command</p>
<pre>
$ script/generate scaffold item
</pre>
<p>Open http://localhost:3000/items and if you see something like this </p>
<pre>
Listing items

Name

New item
</pre>
<p>you have everything needed to get started with Rails development so <a href="http://www.rubyonrails.org/docs">Enjoy</a>!</p>
<p><!-- technorati tags start -->
<p style="text-align:right;font-size:10px;">Technorati Tags: <a href="http://www.technorati.com/tag/mac" rel="tag">mac</a>, <a href="http://www.technorati.com/tag/osx" rel="tag">osx</a>, <a href="http://www.technorati.com/tag/rails" rel="tag">rails</a>, <a href="http://www.technorati.com/tag/ruby" rel="tag">ruby</a></p>
<p><!-- technorati tags end --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kolodvor.net/2007/07/25/quick-start-with-rails-on-os-x/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

