<?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>We Eat Bricks :: Web Development Blog &#187; Rails</title>
	<atom:link href="http://weeatbricks.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://weeatbricks.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 23 May 2010 12:08:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Problem with creating a new file in Ruby on WinXp</title>
		<link>http://weeatbricks.com/2008/03/13/problem-with-creating-a-new-file-in-ruby-on-winxp/</link>
		<comments>http://weeatbricks.com/2008/03/13/problem-with-creating-a-new-file-in-ruby-on-winxp/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 15:16:15 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.weeatbricks.com/2008/03/13/problem-with-creating-a-new-file-in-ruby-on-winxp/</guid>
		<description><![CDATA[I came across this problem today. I was attempting to create a new binary file using Ruby and tried the following:
File.new(&#8221;picture.jpg&#8221;, &#8220;w&#8221;)
While this worked on the *nix os, it resulted in a corrupt binary file when run in WINXP.
Solution
To create a binary file in ruby you will need to include the &#8220;wb&#8221; option. See below.
File.new(&#8221;picture.jpg&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this problem today. I was attempting to create a new binary file using Ruby and tried the following:</p>
<div class="code">File.new(&#8221;picture.jpg&#8221;, &#8220;w&#8221;)</div>
<p>While this worked on the *nix os, it resulted in a corrupt binary file when run in WINXP.</p>
<h3>Solution</h3>
<p>To create a binary file in ruby you will need to include the &#8220;wb&#8221; option. See below.</p>
<div class="code">File.new(&#8221;picture.jpg&#8221;, &#8220;wb&#8221;)</div>
<p>Bye!</p>
]]></content:encoded>
			<wfw:commentRss>http://weeatbricks.com/2008/03/13/problem-with-creating-a-new-file-in-ruby-on-winxp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful Rails 2 tutorials</title>
		<link>http://weeatbricks.com/2008/02/05/useful-rails-2-tutorials/</link>
		<comments>http://weeatbricks.com/2008/02/05/useful-rails-2-tutorials/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 23:29:45 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.weeatbricks.com/2008/02/05/useful-rails-2-tutorials/</guid>
		<description><![CDATA[If you are starting out with Ruby on Rails you&#8217;ll probably find yourself working on the depot application from the current edition of the book &#8220;Agile Web development with Rails&#8221;. However if you have Rails 2 installed you&#8217;ll quickly run into problems.  The current edition of &#8220;Agile Web Development with Rails&#8221; supports rails 1.X. [...]]]></description>
			<content:encoded><![CDATA[<p>If you are starting out with Ruby on Rails you&#8217;ll probably find yourself working on the depot application from the current edition of the book &#8220;Agile Web development with Rails&#8221;. However if you have Rails 2 installed you&#8217;ll quickly run into problems.  The current edition of &#8220;Agile Web Development with Rails&#8221; supports rails 1.X.  However with the release of Rails 2 key changes in the framework render the instructions for creating the depot application obsolete.</p>
<p>To get up to speed you should find the following tutorials useful, the first 2 deal with the rails 2 method of creating a basic depot application while along the way showcasing the new features of Rails2.</p>
<p><a href="http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial" class="external">http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial<o:p></o:p></a></p>
<p><a href="http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial-part-2" class="external">http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial-part-2<o:p></o:p></a></p>
<p>I&#8217;ve also found this <a href="http://peepcode.com/products/rails2-pdf" class="external">next PDF </a> informative. It costs 9 dollars but for that you get 140 odd pages of Rails2 goodness that should fill the void until they get around to updating &#8220;&#8221;Agile Web Development with Rails&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://weeatbricks.com/2008/02/05/useful-rails-2-tutorials/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to use a Rails App with HTTPS</title>
		<link>http://weeatbricks.com/2007/10/31/how-to-use-a-rails-app-with-https/</link>
		<comments>http://weeatbricks.com/2007/10/31/how-to-use-a-rails-app-with-https/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 13:08:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.weeatbricks.com/2007/10/31/how-to-use-a-rails-app-with-https/</guid>
		<description><![CDATA[Summary
We need to provide HTTPS support to test your rails application on your local server. Sensitive data such as passwords are submitted during login and register stages and we want to encrypt the transmission of this data between the client browser and the server. The HTTPS protocol proves this security. 
 
For developing we currently [...]]]></description>
			<content:encoded><![CDATA[<h2>Summary</h2>
<p class="MsoNormal"><span style="font-family: Arial">We need to provide HTTPS support to test your rails application on your local server. Sensitive data such as passwords are submitted during login and register stages and we want to encrypt the transmission of this data between the client browser and the server. The HTTPS protocol proves this security. <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">For developing we currently run the Mongrel server. To achieve HTTPS we need to put an Apache server in front of this Mongrel server. The Apache handles the SSL encryption, certificates etc and acts as a type of proxy to the Mongrel rails server.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">The end result of the following steps is a Rails app that works with HTTPS.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<h2>Install SSL enabled Apache</h2>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Install an SSL enabled Apache. The fastest and most convenient method I’ve found is the XAMPP installer.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">It’s a one click installer. Download and run. SSL enabled Apache is one of the programs installed that’s what we’re interested in. Ignore the rest (PHP etc).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">WINXP<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><a href="http://www.apachefriends.org/en/xampp-windows.html">http://www.apachefriends.org/en/xampp-windows.html</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">MAC OSX<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><a href="http://www.apachefriends.org/en/xampp-macosx.html">http://www.apachefriends.org/en/xampp-macosx.html</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Or if you’re feeling brave install and configure an SSL enabled Apache yourself.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">NOTE: mySQL is also installed with XAMPP. However if it causes confilict with your exisintg mySQL you can turn it off via the provided admin panel/command line and use your existing mySQL.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<h2>Configure Apache to work Mongrel</h2>
<p class="MsoNormal"><span style="font-family: Arial">Having insalled the XAMPP you will have an Apache directory conf that contains the Apache configuration files.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Edit the Apache file conf/httpd.conf.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Uncomment the following lines:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial">LoadModule proxy_module modules/mod_proxy.so<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">and other proxy modules mentioned.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Also uncomment <o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial">LoadModule headers_module modules/mod_headers.so<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">In the Apache file conf/extra/httpd-vhosts.conf edit the following: <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Make sure this line exists<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial">NameVirtualHost *:80<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Add the following vhost<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left: 36pt"><span style="font-family: Arial">&lt;VirtualHost *:80&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 36pt"><span style="font-family: Arial"><span>    </span>ServerName </span><span style="font-family: Arial"></span><span style="font-family: Arial">Mydomain</span></p>
<p class="MsoNormal" style="margin-left: 36pt"><span style="font-family: Arial"><span>    </span>ProxyPass / http://localhost:3002/<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 36pt"><span style="font-family: Arial"><span>    </span>ProxyPassReverse / http://localhost:3002<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 36pt"><span style="font-family: Arial">&lt;/VirtualHost&gt;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">To make the above vhost work for us we also need to edit the hosts file in WinXP.  Mydomain<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">WinXP<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">C:\WINDOWS\system32\drivers\etc\hosts <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial">127.0.0.1 </span><span style="font-family: Arial">Mydomain</span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">And on the MacOSX, add the same to the </span><code><em><span style="font-family: Arial">/etc/hosts<o:p></o:p></span></em></code></p>
<p class="MsoNormal"><code><em><span style="font-family: Arial"><o:p> </o:p></span></em></code></p>
<p class="MsoNormal"><em><span style="font-family: Arial"><o:p> </o:p></span></em></p>
<h2>Start the Apache server</h2>
<p class="MsoNormal"><span style="font-family: Arial">At this point you will have Apache server set up. Start the Apache server. <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Test your Apache is running, browse to <a href="http://localhost/">http://localhost</a>, you’ll get the Apache XAMPP page with some useful tools.<o:p></o:p></span></p>
<h2><o:p> </o:p></h2>
<h2>Start the mongrel server</h2>
<p class="MsoNormal"><span style="font-family: Arial">At this point you will have Apache running so start Mongrel<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial">ruby script/server -p 3002<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Now browse to <a href="http://o2bp/">http://</a></span><a href="http://o2bp/"><span style="font-family: Arial">Mydomain</span></a></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Browsing to the URL <a href="http://o2bp/">http://</a></span><a href="http://o2bp/"><span style="font-family: Arial">Mydomain</span></a><span style="font-family: Arial"> takes you to localhost (127.0.0.1) via hosts file you edited and there an Apache vhost checks the URL, and sees that it is </span><span style="font-family: Arial">Mydomain</span><span style="font-family: Arial"> then passes it onto the Mongrel server running http://localhost:3002<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<h2>Enable HTTPS</h2>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family: Arial">Configure Apache to use SSL and configure Mongrel to know about it<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Edit the Apache file conf/extra/httpd-ssl.conf<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 18pt"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left: 18pt"><span style="font-family: Arial">Inside the vhost &lt;VirtualHost _default_:443&gt;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Comment out<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 18pt"><span style="font-family: Arial"><span>  </span><span>    </span><span> </span>DocumentRoot &#8220;C:/xampp/htdocs&#8221;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Put in the following<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 18pt"><span style="font-family: Arial"><span>    </span>ServerName </span><span style="font-family: Arial">Mydomain</span><span style="font-family: Arial">:443<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 18pt"><span style="font-family: Arial"><span>    </span>ProxyPass / http://localhost:3002/<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 18pt"><span style="font-family: Arial"><span>    </span>ProxyPassReverse / http://localhost:3002<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial">RequestHeader set X_FORWARDED_PROTO &#8220;https&#8221;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">At this stage start your development environment is set up. Just start Apache, and Mysql then run your rails app and browse to <a href="http://o2bp/">http://</a></span><a href="http://o2bp/"><span style="font-family: Arial">Mydomain</span></a><span style="font-family: Arial"> to view it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Now requests to https:// urls in Rails app should work.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<h2>Set up Rails to work with SSL protocol</h2>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family: Arial">The following steps were required to set up the rails app to work with the SSL protocol.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Make sure that the SSL <span> </span>plug-in for Rails is installed.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-indent: 36pt"><span style="font-family: Arial">ruby script/plugin install ssl_requirement<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Next edit the ApplicationController, add the line ‘include SslRequirement ‘<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left: 36pt"><span style="font-family: Arial">class ApplicationController &lt; ActionController::Base<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left: 36pt"><span style="font-family: Arial"><span> </span><span>           </span><span> </span>include SslRequirement<span>  </span><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Now you can set policies for individual actions in each of the controllers.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">EG <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">In the AuthController we want the login and the authenticate action accessible via SSL only.</span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal">class AuthController &lt; ApplicationController</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">ssl_required :login, :authenticate</p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">Now requests to http://Mydomain/login will redirect to https://</span> <span style="font-family: Arial">Mydomain</span><span style="font-family: Arial">/login<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial">The End.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<h2>References</h2>
<p class="MsoNormal"><span style="font-family: Arial"><a href="http://blog.innerewut.de/2006/6/21/mongrel-and-rails-behind-apache-2-2-and-ssl">Mongrel and Rails behind Apache 2.2 and SSL</a></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><a href="http://blog.innerewut.de/2006/06/21/mongrel-and-rails-behind-apache-2-2-and-ssl#comment-form">http://blog.innerewut.de/2006/06/21/mongrel-and-rails-behind-apache-2-2-and-ssl#comment-form</a><o:p></o:p></span></p>
<p class="MsoNormal"><em><span style="font-family: Arial"><span> </span>“Agile Web development with Rails”, Page 612<o:p></o:p></span></em></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family: Arial"><o:p> </o:p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://weeatbricks.com/2007/10/31/how-to-use-a-rails-app-with-https/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
