<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Meon Love Meehon &#187; Ruby on Rails</title>
	<atom:link href="http://meehon.wordpress.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://meehon.wordpress.com</link>
	<description>"with great power comes great responsibility"</description>
	<lastBuildDate>Fri, 18 Dec 2009 05:03:06 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='meehon.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/75d0d9c3f464148cfe8c27a8c971015e?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Meon Love Meehon &#187; Ruby on Rails</title>
		<link>http://meehon.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://meehon.wordpress.com/osd.xml" title="Meon Love Meehon" />
		<item>
		<title>Ruby on Rails Wiki</title>
		<link>http://meehon.wordpress.com/2009/04/23/ruby-on-rails-wiki/</link>
		<comments>http://meehon.wordpress.com/2009/04/23/ruby-on-rails-wiki/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 08:31:03 +0000</pubDate>
		<dc:creator>meehon</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://meehon.wordpress.com/?p=158</guid>
		<description><![CDATA[

Install Ruby/Rails for your particular platform, and make sure you have SQLite installed (this comes with a Mac if you have a Mac). Installation wiki pages can be found here: Mac, Windows, Linux.




Run the Rails command line tool to create the application. 
$ rails myapp
This will create the skeleton of your Rails app.


Go into your directory, probably by typing: 
$ [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meehon.wordpress.com&blog=4376815&post=158&subd=meehon&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2><a name="part_1_-_installation"></a></h2>
<div class="level2">
<p>Install Ruby/Rails for your particular platform, and make sure you have SQLite installed (this comes with a Mac if you have a Mac). Installation wiki pages can be found here: <a class="wikilink1" title="getting-started:installation:mac" href="http://wiki.rubyonrails.org/getting-started/installation/mac">Mac</a>, <a class="wikilink1" title="getting-started:installation:windows" href="http://wiki.rubyonrails.org/getting-started/installation/windows">Windows</a>, <a class="wikilink1" title="getting-started:installation:linux" href="http://wiki.rubyonrails.org/getting-started/installation/linux">Linux</a>.</div>
<h2><a name="part_2_-_create_run"></a></h2>
<div class="level2">
<ol>
<li class="level1">
<div class="li">Run the Rails command line tool to create the application. </p>
<pre class="code">$ rails myapp</pre>
<p>This will create the skeleton of your Rails app.</p></div>
</li>
<li class="level1">
<div class="li">Go into your directory, probably by typing: </p>
<pre class="code">$ cd myapp</pre>
</div>
</li>
<li class="level1">
<div class="li">Startup your Rails server by running: </p>
<pre class="code">$ ruby script/server</pre>
<p><em><a class="media" title="getting-started:installation:information.png" href="http://wiki.rubyonrails.org/_detail/getting-started/installation/information.png?id=getting-started%3Afirst-rails-app-walkthrough&amp;cache=cache"><img class="media" src="http://wiki.rubyonrails.org/_media/getting-started/installation/information.png?w=&amp;h=&amp;cache=cache" alt="" /></a>Note: You may not need the “ruby” part of that if you&#8217;re on a Mac or Linux.</em></div>
</li>
<li class="level1">
<div class="li">Call up a browser and go to <a class="urlextern" title="http://localhost:3000" rel="nofollow" href="http://localhost:3000/">http://localhost:3000</a>. You should see that Rails is running; that&#8217;s all there is to it! Pat yourself on the back, you deserve it.</div>
</li>
</ol>
</div>
<h2><a name="part_3_-_creating_the_database_scaffold"></a></h2>
<div class="level2">
<ol>
<li class="level1">
<div class="li">Open the application in your editor of choice.</div>
</li>
<li class="level1">
<div class="li">Open the <code>config/database.yml</code> file. This is where you would typically configure different databases for your application, but for the sake of this example you shouldn&#8217;t have to touch anything. The default database names, as you may have noticed, are taken from the name of your Rails app.</div>
</li>
<li class="level1">
<div class="li">Open up another command prompt (that way we can keep the server running in the background), and in your application directory run: </p>
<pre class="code">$ rake db:create</pre>
<p>This will create your development database.</p></div>
</li>
<li class="level1">
<div class="li">Now we want to create our first table and interface. In Rails, this typically means we&#8217;re going to create a <a class="urlextern" title="http://guides.rubyonrails.org/getting_started_with_rails.html#_getting_up_and_running_quickly_with_scaffolding" rel="nofollow" href="http://guides.rubyonrails.org/getting_started_with_rails.html#_getting_up_and_running_quickly_with_scaffolding">scaffold</a>to start from. A scaffold is simply a starting point, and we can add increasingly complex code from there. Let&#8217;s first run the scaffold command without any parameters: </p>
<pre class="code">$ ruby script/generate scaffold</pre>
<p>Take a look at the output generated. It shows you how to use the command.</p></div>
</li>
<li class="level1">
<div class="li">Now let&#8217;s go ahead and use scaffold to start generating our web application. We&#8217;re going to create a users table: </p>
<pre class="code">$ ruby script/generate scaffold user first_name:string last_name:string active:boolean</pre>
<p>It&#8217;s okay if you copy and paste this code, I won&#8217;t tell anyone. So now your scaffold is created, which is just a bunch of template files.</p></div>
</li>
<li class="level1">
<div class="li">Let&#8217;s <a class="urlextern" title="http://guides.rubyonrails.org/getting_started_with_rails.html#_running_a_migration" rel="nofollow" href="http://guides.rubyonrails.org/getting_started_with_rails.html#_running_a_migration">run the migration</a> it created for us (to create the database table). </p>
<pre class="code">$ rake db:migrate</pre>
</div>
</li>
<li class="level1">
<div class="li">Now go back to your browser (start your server back up if you killed it), and go to <a class="urlextern" title="http://localhost:3000/users" rel="nofollow" href="http://localhost:3000/users">http://localhost:3000/users</a></div>
</li>
<li class="level1">
<div class="li">Create a few users, and play around with your Rails interface!</div>
</li>
</ol>
</div>
<h2><a name="part_4_-_adding_functionality"></a></h2>
<div class="level2">
<ol>
<li class="level1">
<div class="li">We just realized that we forgot to add a bio field for a user &#8211; oops! We could either create a new migration to add that column, or roll back the migration that was created for us. Let&#8217;s do the latter. To remove the table so we can add a column, run this command: </p>
<pre class="code">$ rake db:rollback</pre>
<p>This will roll back one migration.</p></div>
</li>
<li class="level1">
<div class="li">Now open the migration located in the <code>/db/migrations/</code> directory. It should be the only file.</div>
</li>
<li class="level1">
<div class="li">Notice how the migration has an <code>up</code> method to migrate up, and <code>down</code> method to migrate down.</div>
</li>
<li class="level1">
<div class="li">We want to add that bio field, so after the <code>t.boolean :active</code> line, add: </p>
<pre class="code ruby">t.<span class="me1">text</span> <span class="re3">:bio</span></pre>
</div>
</li>
<li class="level1">
<div class="li">Save the file, and run <code>rake db:migrate</code> again to migrate your database up: </p>
<pre class="code">$ rake db:migrate</pre>
</div>
</li>
<li class="level1">
<div class="li">If you checked your browser at this point, you&#8217;d notice that the bio field isn&#8217;t automatically showing up in our user&#8217;s information or forms. We will need to add this ourselves. Yes, we could have erased the files and run the scaffold command to get this field, but then you wouldn&#8217;t learn anything.</div>
</li>
<li class="level1">
<div class="li">Lets open up the <code>/app/views/users/new.html.erb</code> file. This is what renders our New User form. We need to add a bio field using the following code below the active checkbox. </p>
<pre class="code ruby"><span class="sy0">&lt;</span>p<span class="sy0">&gt;</span>
  <span class="sy0">&lt;%</span>= f.<span class="me1">label</span> <span class="re3">:bio</span> <span class="sy0">%&gt;&lt;</span>br <span class="sy0">/&gt;</span>
  <span class="sy0">&lt;%</span>= f.<span class="me1">text_area</span> <span class="re3">:bio</span> <span class="sy0">%&gt;</span>
<span class="sy0">&lt;/</span>p<span class="sy0">&gt;</span></pre>
</div>
</li>
<li class="level1">
<div class="li">Now open up the New User page in your browser <a class="urlextern" title="http://localhost:3000/users/new" rel="nofollow" href="http://localhost:3000/users/new">http://localhost:3000/users/new</a>. You should see the bio field, and be able to add new users with a bio. <a class="media" title="getting-started:installation:information.png" href="http://wiki.rubyonrails.org/_detail/getting-started/installation/information.png?id=getting-started%3Afirst-rails-app-walkthrough&amp;cache=cache"><img class="media" src="http://wiki.rubyonrails.org/_media/getting-started/installation/information.png?w=&amp;h=&amp;cache=cache" alt="" /></a> For extra credit, you could use the same code if you wanted to update the <code>edit</code> view (in <code>/app/views/users/edit.html.erb</code>) so you can edit a user&#8217;s bio.</div>
</li>
<li class="level1">
<div class="li">When you create a user, you&#8217;re brought automatically to his/her show page. Let&#8217;s add the bio to the show page. You can do this by opening the <code>/app/views/users/show.html.erb</code> file, and underneath the Active field, adding: </p>
<pre class="code ruby"><span class="sy0">&lt;</span>p<span class="sy0">&gt;</span>
  <span class="sy0">&lt;</span>b<span class="sy0">&gt;</span>Bio:<span class="sy0">&lt;/</span>b<span class="sy0">&gt;</span>
  <span class="sy0">&lt;%</span>=h <span class="re1">@user</span>.<span class="me1">bio</span> <span class="sy0">%&gt;</span>
<span class="sy0">&lt;/</span>p<span class="sy0">&gt;</span></pre>
</div>
</li>
<li class="level1">
<div class="li">Save the file and check it out in the browser. If you don&#8217;t see your change at first, make sure you are on the <code>show</code>page (and not the <code>index</code>). When you get to this part, let out a barbaric “woot!”, you&#8217;ve made some great progress.</div>
</li>
</ol>
</div>
<h2><a name="part_5_-_your_first_validation"></a></h2>
<div class="level2">
<ol>
<li class="level1">
<div class="li">In Rails, we put our validations in our model files, so let&#8217;s open <code>/app/models/user.rb</code>.</div>
</li>
<li class="level1">
<div class="li">We want to require that a user enter their first name and last name, so let&#8217;s add validation to our User model, so it ends up looking like this: </p>
<pre class="code ruby"><span class="kw1">class</span> User <span class="sy0">&lt;</span> <span class="re2">ActiveRecord::Base</span>
  validates_presence_of <span class="re3">:first_name</span>, <span class="re3">:last_name</span>
<span class="kw1">end</span></pre>
</div>
</li>
<li class="level1">
<div class="li">Save the file, go to your browser, and attempt to create a user without a first name or last name.</div>
</li>
<li class="level1">
<div class="li">Rails has many helper validation classes, and you can see a list on the right side <a class="urlextern" title="http://apidock.com/rails/ActiveRecord/Validations/ClassMethods" rel="nofollow" href="http://apidock.com/rails/ActiveRecord/Validations/ClassMethods">of this API page</a>.</div>
</li>
</ol>
<p><a class="media" title="getting-started:installation:information.png" href="http://wiki.rubyonrails.org/_detail/getting-started/installation/information.png?id=getting-started%3Afirst-rails-app-walkthrough&amp;cache=cache"><img class="media" src="http://wiki.rubyonrails.org/_media/getting-started/installation/information.png?w=&amp;h=&amp;cache=cache" alt="" /></a> For extra credit, add another validation to your app just for fun.</div>
<h2><a name="part_6_-_modifying_the_layout"></a></h2>
<div class="level2">
<ol>
<li class="level1">
<div class="li">If you viewed the browser <acronym title="HyperText Markup Language">HTML</acronym> source of your application, you may have noticed that your application is in some sort of layout. By default, when you ran the <code>scaffold</code> command, a <code>/app/views/layouts/users.html.erb</code> file was created, and used as your layout.</div>
</li>
<li class="level1">
<div class="li">You&#8217;ll probably only want to use one layout for most of your controllers, so let&#8217;s give this a more generic name. Rename <code>users.html.erb</code> to <code>application.html.erb</code>. As a Rails convention, now that you have an<code>application.html.erb</code> file in your layouts directory, all controllers will use this by default (you can override this later if you want).</div>
</li>
<li class="level1">
<div class="li">Let&#8217;s add something to our layout just for fun. Open up the <code>application.html.erb</code> and add something like: </p>
<pre class="code html">&lt;h2&gt;Rails Rocks!&lt;/h2&gt;</pre>
</div>
</li>
<li class="level1">
<div class="li">Save the file, go to your browser, and you should see the change you made reflected on ALL pages of the website.</div>
</li>
</ol>
</div>
<h2><a name="part_7_-_having_fun_with_the_console"></a></h2>
<div class="level2">
<ol>
<li class="level1">
<div class="li">Let&#8217;s have some fun playing with our User Model. In your command prompt, type: </p>
<pre class="code">$ ruby script/console</pre>
<p>You are now in a Ruby IRB session which has access to your models.</p></div>
</li>
<li class="level1">
<div class="li">Before we start playing, run the following command so that we can see what <acronym title="Structured Query Language">SQL</acronym> commands are going to be generated for us. </p>
<pre class="code">$ ActiveRecord::Base.logger = Logger.new(STDOUT)</pre>
</div>
</li>
<li class="level1">
<div class="li">Let&#8217;s try a simple Ruby statement to make sure everything is working: </p>
<pre class="code ruby"><span class="kw3">puts</span> <span class="st0">"Hello Dude!"</span></pre>
</div>
</li>
<li class="level1">
<div class="li">Now let&#8217;s try having some fun with our model. Create a new model by doing something like this: </p>
<pre class="code ruby">u = User.<span class="me1">new</span>
u.<span class="me1">first_name</span> = <span class="st0">"Gregg"</span>
u.<span class="me1">last_name</span> = <span class="st0">"Pollack"</span>
u.<span class="me1">save</span></pre>
<p>Notice the <acronym title="Structured Query Language">SQL</acronym> that is generated.</div>
</li>
<li class="level1">
<div class="li">Now try doing it all in a single line: </p>
<pre class="code ruby">User.<span class="me1">create</span><span class="br0">(</span><span class="re3">:first_name</span> <span class="sy0">=&gt;</span> <span class="st0">"Joe"</span>, <span class="re3">:last_name</span> <span class="sy0">=&gt;</span> <span class="st0">"Blow"</span><span class="br0">)</span></pre>
<p>If you hit any errors, check for syntax problems.</p></div>
</li>
<li class="level1">
<div class="li">Let&#8217;s fetch the user with first name of Joe, and change his last name to “Johnson”. </p>
<pre class="code ruby">u = User.<span class="me1">find_by_first_name</span><span class="br0">(</span><span class="st0">"Joe"</span><span class="br0">)</span>
u.<span class="me1">last_name</span> = <span class="st0">"Johnson"</span>
u.<span class="me1">save</span></pre>
<p>Notice the <acronym title="Structured Query Language">SQL</acronym> that gets generated; nice!</div>
</li>
<li class="level1">
<div class="li">Now let&#8217;s delete the user. </p>
<pre class="code ruby">u.<span class="me1">destroy</span></pre>
</div>
</li>
<li class="level1">
<div class="li">Have some fun trying the following commands to see what they do: </p>
<pre class="code ruby">User.<span class="me1">first</span>
User.<span class="me1">last</span>
User.<span class="me1">all</span></pre>
<p>Feel free to set a variable with the values, and play around with changing attributes. Do note that <code>.all</code> returns an array, so you may want to use [0] or [2] to refer to a particular item in the array.</div>
</li>
<li class="level1">
<div class="li">Let&#8217;s print out all the users in your system in upper case: </p>
<pre class="code ruby">User.<span class="me1">all</span>.<span class="me1">each</span> <span class="br0">{</span><span class="sy0">|</span>user<span class="sy0">|</span> <span class="kw3">puts</span> user.<span class="me1">first_name</span>.<span class="me1">upcase</span> <span class="br0">}</span></pre>
</div>
</li>
<li class="level1">
<div class="li">You&#8217;ll notice that it prints out the first names, and then it also returns the array of Users. Remember, every method in Ruby returns something, even if it&#8217;s nil.</div>
</li>
<li class="level1">
<div class="li">Let&#8217;s create an array of all of the last names in our system: </p>
<pre class="code ruby">User.<span class="me1">all</span>.<span class="me1">map</span> <span class="br0">{</span><span class="sy0">|</span>user<span class="sy0">|</span> user.<span class="me1">last_name</span> <span class="br0">}</span></pre>
<p>What we&#8217;re interested in here is the return value, which should be an array of last names.</p></div>
</li>
<li class="level1">
<div class="li">Take a look at the <a class="urlextern" title="http://apidock.com/rails/ActiveRecord/Base" rel="nofollow" href="http://apidock.com/rails/ActiveRecord/Base">API page here</a>. Along the right you&#8217;ll see all of the methods you can run on ActiveRecord objects. Try a few.</div>
</li>
</ol>
</div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meehon.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meehon.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meehon.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meehon.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meehon.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meehon.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meehon.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meehon.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meehon.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meehon.wordpress.com/158/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meehon.wordpress.com&blog=4376815&post=158&subd=meehon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://meehon.wordpress.com/2009/04/23/ruby-on-rails-wiki/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ab202be7c6a7f8e0706c6eb78118c72?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meehon</media:title>
		</media:content>

		<media:content url="http://wiki.rubyonrails.org/_media/getting-started/installation/information.png?w=&#38;h=&#38;cache=cache" medium="image" />

		<media:content url="http://wiki.rubyonrails.org/_media/getting-started/installation/information.png?w=&#38;h=&#38;cache=cache" medium="image" />

		<media:content url="http://wiki.rubyonrails.org/_media/getting-started/installation/information.png?w=&#38;h=&#38;cache=cache" medium="image" />
	</item>
		<item>
		<title>Rails on Vista</title>
		<link>http://meehon.wordpress.com/2009/04/23/rail-on-vista/</link>
		<comments>http://meehon.wordpress.com/2009/04/23/rail-on-vista/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 08:28:55 +0000</pubDate>
		<dc:creator>meehon</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://meehon.wordpress.com/?p=155</guid>
		<description><![CDATA[If you are like me, you usually develop RoR applications on linux (I am talking about non-mac people, anyway…).  My setup is usually looks like this : XUbuntu + Netbeans  + Mysql/Sqlite3 + Apache + Phusion Passanger.  Assuming you got all your development done andi it’s called  “MyApp”.
On Windows 2008 Box
Step 1:  Install Ruby, gems [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meehon.wordpress.com&blog=4376815&post=155&subd=meehon&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you are like me, you usually develop RoR applications on linux (I am talking about non-mac people, anyway…).  My setup is usually looks like this : XUbuntu + Netbeans  + Mysql/Sqlite3 + Apache + Phusion Passanger.  Assuming you got all your development done andi it’s called  “MyApp”.</p>
<p><strong>On Windows 2008 Box</strong></p>
<p><strong>Step 1:  Install Ruby, gems and rails</strong></p>
<p>Get <a href="http://rubyforge.org/frs/download.php/29263/ruby186-26.exe">Ruby 1.8.6 One-Click Installer</a> (from http://www.ruby-lang.org/en/downloads/) and make sure to install gems.</p>
<p>Then installing rails is a breeze. Open a command line window and type</p>
<address>gem install rails –include-dependencies</address>
<p><strong>Step 2: Install mongrel &amp; mongrel_service</strong></p>
<address>gem install mongrel</address>
<address>gem install mongrel_service</address>
<p><strong>Step 3 : Install Apache and enable required modules</strong></p>
<p>A. Get Latest msi version for windows (currently <a href="http://mirror.jimbojay.com/apache/httpd/binaries/win32/apache_2.2.10-win32-x86-no_ssl.msi">apache_2.2.10-win32-x86-no_ssl.msi</a>) from http://httpd.apache.org/download.cgi</p>
<p>B. Install as a service.</p>
<p>C. Enable required modules by uncommenting these following line in http.conf file (which can be found at C:Program Files (x86)Apache Software FoundationApache2.2conf</p>
<p>if you followed the default installation)</p>
<address>LoadModule rewrite_module modules/mod_rewrite.so</address>
<address>LoadModule proxy_module modules/mod_proxy.so</address>
<address>LoadModule proxy_balancer_module modules/mod_proxy_balancer.so</address>
<address>LoadModule proxy_http_module modules/mod_proxy_http.so</address>
<p>D. Start the server to makesure it starts and runs OK. If there is a problem with config file you would see an error.</p>
<p><strong>Step 4 : Install database drivers</strong></p>
<p>This really depends on your database. Remember that for sqlite3, if you are having trouble installing latest</p>
<p>drivers, try giving a version no as follows.</p>
<address>gem install –version 1.2.3 sqlite3-ruby</address>
<p><strong>Step 5 : Create a skeleton rails application</strong></p>
<p>I am assuming we are keeping our rails application in C:railsapps</p>
<p>So create the new rails application by changing to that directory and running</p>
<address>rails Myapp</address>
<p>The reason for creating a skeleton instead of just copying our application from Linux, is that the way some files are created on windows may not be same as linux.  So let it create a dummy app and test it to make sure, its able to pullup the welcome page.</p>
<p><strong>Step 6 : Copy your application Files over to windows</strong></p>
<p>The directories usually copy are</p>
<address>app/      all directories below</address>
<address>public/   any static files you created,  directories  stylesheets, javascripts and images.</address>
<address>config/   routes.rb, database.yml</address>
<address>db/        schema.rb</address>
<p>(Again, this is highly dependent on your application. May be you didn’t have any custom javascripts or stylesheets in that case you could skip public/ folder all together)</p>
<p><strong>Step 7:  Load Database Schema into production db</strong></p>
<address>rake db:schema:load RAILS_ENV=production</address>
<address></address>
<p><strong>Step 8 : Create Multiple Mongrel Server Instances and start them as automatic</strong></p>
<p>I am creating 3 instances here</p>
<address>mongrel_rails service::install -N mongrel_Myapp1 -p 3001 -e production -c c:railsappsMyapp</address>
<address>mongrel_rails service::install -N mongrel_Myapp2 -p 3002 -e production -c c:railsappsMyapp</address>
<address>mongrel_rails service::install -N mongrel_Myapp3 -p 3003 -e production -c c:railsappsMyapp</address>
<p>which creates three services (you could see them Start&gt;&gt;Administrative Tools &gt;&gt; Services Panel). By default the services are created as  “Startup Type — Manual”. Set that to “Automatic” so that they will start back again if you reboot the server.</p>
<p><strong>Step 9: Setup Apache</strong></p>
<p class="text">In the apache’s http.conf file make sure to have these following lines</p>
<address># Virtual hosts</address>
<address>Include conf/extra/httpd-vhosts.conf</address>
<p>Then make your  conf/extra/httpd-vhosts.conf  File look like this</p>
<p>#——- Start of http-vhosts.conf file ———————————–</p>
<address>NameVirtualHost *:80</address>
<address>#Proxy balancer section (create one for each ruby app cluster)</address>
<address>&lt;Proxy balancer://Myapp_cluster&gt;</address>
<address>BalancerMember http://127.0.0.1:3001</address>
<address>BalancerMember http://127.0.0.1:3002</address>
<address>BalancerMember http://127.0.0.1:3003</address>
<address>&lt;/Proxy&gt;</address>
<address>&lt;VirtualHost *:80&gt;</address>
<address>DocumentRoot “C:/railsapps/Myapp/public”</address>
<address>ErrorLog “logs/Myapp-error.log”</address>
<address>CustomLog “logs/Myapp-access.log” common</address>
<address></address>
<address>&lt;Directory C:/railsapps/Myapp/public/ &gt;</address>
<address>Options Indexes FollowSymLinks MultiViews</address>
<address>AllowOverride All</address>
<address>Order allow,deny</address>
<address>allow from all</address>
<address>&lt;/Directory&gt;</address>
<address></address>
<address>RewriteEngine On</address>
<address># Rewrite index to check for static files</address>
<address>RewriteRule ^/$ /index.html [QSA]</address>
<address># Rewrite to check for Rails cached pages</address>
<address>RewriteRule ^([^.]+)$ $1.html [QSA]</address>
<address># Redirect all non-static requests to cluster</address>
<address>RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f</address>
<address>RewriteRule ^/(.*)$ balancer://Myapp_cluster%{REQUEST_URI} [P,QSA,L]</address>
<address>&lt;/VirtualHost&gt;</address>
<address>#——- End of http-vhosts.conf file ———————————–</address>
<p>If you ever used apache’s mod_rewrite module then you dont need any explanation. If you don’t, then breif explanation wont make much sense to you either….</p>
<p>Becareful with name of Proxy balancer and make sure to use exact name in last RewriteRule (in the above case its Myapp_cluster), then you should be fine.</p>
<p><strong>Step 10 :  Start the mongrel services and Restart Apache.</strong></p>
<p>Now when you go to http://localhost/  you should be sent to one of the 3 servers of balancer and see the application.  If you see broken images or ugly layout, then it means you didnt copy my “http-vhosts.conf” file properly!  Have a careful look at &lt;Directory&gt; directive again. You would know.</p>
<p>Happy programming and happy holidays.  Ciao.</p>
<p>p.s.  If you want to run multiple rails applications on same server like MyApp1, MyApp2…., have a look at rails.conf I used in “<a href="http://nlakkakula.wordpress.com/2007/07/19/setting-up-rails-production-server-using-apache2-mongrel-cluster-on-fedora-core-5/">Fedora production setup</a>“. By adding another balancer and modifing RewriteRules littlebit, its not that tough.</p>
<p> </p>
<p> </p>
<p>Here is a quick add-on &#8211; How to set up a mongrel service to proxy from Apache!</p>
<p>First, you need the mongrel_rails gem, so install that using</p>
<p><code>gem install mongrel_rails</code></p>
<p>If we are creating a blog application, we want to set it up so that the URL we visit is<a rel="nofollow" href="http://blog/">http://blog/</a>, so you need to open your hosts file, which can be found in C:\WINDOWS\system32\drivers\etc\, and enter the following line:</p>
<p><code>127.0.0.1 blog</code></p>
<p>Then you need to open your Apache config. Where you setup virtual hosts, enter this:</p>
<p> </p>
<p><code>ServerName blog<br />
ServerAlias *.blog</p>
<p>DocumentRoot C:/root/to/your/rails/app's/public/directory</p>
<p>RewriteEngine On</p>
<p># Redirect all non-static requests to Mongrel<br />
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f<br />
RewriteRule ^/(.*)$<a rel="nofollow" href="http://127.0.0.1:7000%/">http://127.0.0.1:7000%</a>{REQUEST_URI} [P,QSA,L]</p>
<p># Custom log file locations<br />
ErrorLog C:/root/to/your/rails/app/logfiles<br />
CustomLog C:/root/to/your/rails/app/logfiles combined</p>
<p></code> </p>
<p>Lastly, go into your command line. Navigate to your rails directory and run this command:</p>
<p><code>mongrel_rails service::install -p 7000 -N MyRailsApp</code></p>
<p>This will install the service. Restart Apache, and run:</p>
<p><code>net start MyRailsApp</code></p>
<p>And you should have a fully working proxy to mongrel!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/meehon.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/meehon.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/meehon.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/meehon.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/meehon.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/meehon.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/meehon.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/meehon.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/meehon.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/meehon.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=meehon.wordpress.com&blog=4376815&post=155&subd=meehon&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://meehon.wordpress.com/2009/04/23/rail-on-vista/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2ab202be7c6a7f8e0706c6eb78118c72?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">meehon</media:title>
		</media:content>
	</item>
	</channel>
</rss>