<?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>Refreshingly Blue &#187; Ruby on Rails</title>
	<atom:link href="http://www.refreshinglyblue.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.refreshinglyblue.com</link>
	<description>Notes by Lee Blue</description>
	<lastBuildDate>Sun, 29 Aug 2010 03:50:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>My 2 Cents On Web Hosting</title>
		<link>http://www.refreshinglyblue.com/2008/07/18/my-2-cents-on-web-hosting/</link>
		<comments>http://www.refreshinglyblue.com/2008/07/18/my-2-cents-on-web-hosting/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 17:16:50 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.refreshinglyblue.com/2008/07/18/my-2-cents-on-web-hosting/</guid>
		<description><![CDATA[People regularly ask me where to host their websites. This is pretty much what I tell everybody.
RackSpace Is The Best
Unless You Don&#8217;t Want To Pay For Managed Hosting Or You Want Ruby on Rails Support
An entry level server at RackSpace will cost you about $500/month. If you can afford a managed, dedicated server, and your [...]]]></description>
			<content:encoded><![CDATA[<p>People regularly ask me where to host their websites. This is pretty much what I tell everybody.</p>
<h2>RackSpace Is The Best</h2>
<h3>Unless You Don&#8217;t Want To Pay For Managed Hosting <br/>Or You Want Ruby on Rails Support</h3>
<p>An entry level server at RackSpace will cost you about $500/month. If you can afford a managed, dedicated server, and your are working with PHP host with <a href="http://www.rackspace.com">RackSpace</a>. I have several servers with RackSpace and have been working with them now for over 5 years. The service, support, and reliability are fantastic unless you intend to host Ruby on Rails applications. RackSpace does not &#8220;officially support&#8221; Rails. When you are talking to the sales department they say they will help with Rails issues even though it&#8217;s not officially supported. My experience is that you are totally on your own with Ruby on Rails at Rackspace.</p>
<h2>RimuHosting Is The Best For Non-Managed Servers</h2>
<h3>The Best VPS, Semi-Dedicated and Dedicated Servers</h3>
<p>So if you want to run Rails apps or you don&#8217;t need a managed dedicated server, host with <a href="http://www.rimuhosting.com">RimuHosting</a>. This blog is hosted at RimuHosting and for the past 2 years I have had both VPS accounts and Dedicated servers there. The uptime, performance and reliability has been extremely good although not quite flawless. There was one time when one of my semi-dedicated VPS accounts was unavailable for about an hour and it was not a scheduled maintenance period. Even with that one blip in the service, my overall experience has been excellent and I highly recommend RimuHosting if you want a VPS account or a non-managed dedicated server. The support is extremely fast and helpful &#8211; albeit via email only. I prefer email though, as long as it&#8217;s attended to promptly. In your customer control panel, you can see the status of your support ticket, how long it has been since you have submitted it, whether or not anyone is working on it, etc. It really is better than phone service in my opinion.</p>
<h2>HostICan</h2>
<h3>The Best Shared Hosting Package I&#8217;ve Ever Seen</h3>
<p>If you just want a <a href="http://secure.hostican.com/cgi-bin/affiliates/clickthru.cgi?id=leehblue">low cost shared hosting</a> account, I have never seen a package that is better than the <a href="http://secure.hostican.com/cgi-bin/affiliates/clickthru.cgi?id=leehblue">BaseHost package with HostICan</a>. It is <strong>$6.95/month</strong> and you get 2,000 GB &#8211; yes about <strong>2 Terabytes</strong> of data storage. You can host 2 different domain names and get a <strong>free domain name for life</strong> when you sign up. The free domain name is at least worth the cost of one month of hosting each year. They offer a <strong>99.9% uptime</strong> guarantee. If you want a WordPress blog, the WordPress software is already there and ready to go. So this is great account to have if you want to <strong>host your own blog</strong>. You can even get <strong>SSH access</strong> but that adds a little to your monthly cost. They no longer support Ruby on Rails. But, if your building Rails apps, get a VPS account at <a href="http://www.rimuhosting.com">RimuHosting</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.refreshinglyblue.com/2008/07/18/my-2-cents-on-web-hosting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How To Implement A Ruby on Rails style before_filter With The PHP Zend Framework</title>
		<link>http://www.refreshinglyblue.com/2008/01/30/how-to-implement-a-ruby-on-rails-style-before_filter-with-the-php-zend-framework/</link>
		<comments>http://www.refreshinglyblue.com/2008/01/30/how-to-implement-a-ruby-on-rails-style-before_filter-with-the-php-zend-framework/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 17:17:55 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.refreshinglyblue.com/2008/01/30/how-to-implement-a-ruby-on-rails-style-before_filter-with-the-php-zend-framework/</guid>
		<description><![CDATA[I often use this when implementing a simple login screen for a password protected section of my application. In a Zend Framework application you can implement a preDispatch() function in a Zend_Controller_Action which will run before an action is dispatched. This lets you setup your filter to check to see if the visitor is logged [...]]]></description>
			<content:encoded><![CDATA[<p>I often use this when implementing a simple login screen for a password protected section of my application. In a <a href="http://framework.zend.com">Zend Framework</a> application you can implement a <a href="http://framework.zend.com/manual/en/zend.controller.plugins.html">preDispatch()</a> function in a Zend_Controller_Action which will run before an action is dispatched. This lets you setup your filter to check to see if the visitor is logged in or not. If the visitor is not logged in, you can redirect them to the login screen of your application.</p>
<h2>Setting Up Exceptions For preDispatch</h2>
<p>If your login screen is managed by a different controller, the setup described above is fine. If, however, your login screen is managed by an action in the same controller as the protected actions, you will want to allow unauthenticated access to the login screen. To do this, we need to exclude certain actions from the authentication check. Ruby on Rails let&#8217;s you define :except =&gt; :actionName to allow certain actions to skip the before_filter. With the Zend Framework, we have to implement that functionality on our own&#8230; but it&#8217;s easy.</p>
<h2>What Action Is Being Called?</h2>
<p>To set up your preDispatch function to skip checking to see if a user is logged in for certain actions you need to know which action is being called. You do that like this&#8230;</p>
<pre>
$action = $this-&gt;_request-&gt;getActionName();
</pre>
<h2>Example Code</h2>
<p>Now all you have to do is see if the action that is being called is one of the actions that you want to skip. I set up a private function called <em>verify()</em> to check whether or not the visitor is logged in. If the user is not logged in, I forward them to the loginAction() function. Since an unauthenticated user needs to be able to access the login screeen, we tell the <em>preDispatch()</em> function not to verify visitors requesting the login action. My controller ends up looking someting like this.</p>
<pre>
class AccountController extends Zend_Controller_Action {

  function preDispatch() {
    // Discover what action is being requested
    $action = $this-&gt;_request-&gt;getActionName();

    // Create a list of actions which allow unauthenticated access
    $exclusions = array("login");
    if(!in_array($action, $exclusions)) {
      $this-&gt;verify();
    }
  }

  /**
   * Check to see if the visitor is logged in. If not, send to loginAction
  */
  private function verifty() {
    $auth = Zend_Auth::getInstance();
    if(!$auth-&gt;hasIdentity()) {
      $this-&gt;_forward("login");
    }
  }

  function loginAction() {
    // Display your login screen
  }

  // Continue the rest of your class...
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.refreshinglyblue.com/2008/01/30/how-to-implement-a-ruby-on-rails-style-before_filter-with-the-php-zend-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How To Remove External Repositories From Subversion</title>
		<link>http://www.refreshinglyblue.com/2008/01/08/how-to-remove-external-repositories-from-subversion/</link>
		<comments>http://www.refreshinglyblue.com/2008/01/08/how-to-remove-external-repositories-from-subversion/#comments</comments>
		<pubDate>Wed, 09 Jan 2008 03:17:11 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.refreshinglyblue.com/2008/01/08/how-to-remove-external-repositories-from-subversion/</guid>
		<description><![CDATA[I was trying out a plugin in my Ruby on Rails application and decided not to use it. Apparently, when I installed the plugin, a reference to it was added to my subversion repository. Since the reference was not to a working directory, my capistrano deployments got debackled and died. Here is how you can [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying out a plugin in my Ruby on Rails application and decided not to use it. Apparently, when I installed the plugin, a reference to it was added to my subversion repository. Since the reference was not to a working directory, my capistrano deployments got debackled and died. Here is how you can remove external repositories from subversion.</p>
<p>If you get a message like this one when you are working with subversion:</p>
<pre>Fetching external item into 'vendor/plugins/...'</pre>
<p>Change directories so that you are in the root of your Rails application and issue the following command:</p>
<pre>svn propedit svn:externals vendor/plugins</pre>
<p>A list of the external plugins will appear in your default editor. Mine is vim. Delete the link that you no longer want, save the file and commit your changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.refreshinglyblue.com/2008/01/08/how-to-remove-external-repositories-from-subversion/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHP vs Ruby &#8211; Practical Language Differences</title>
		<link>http://www.refreshinglyblue.com/2007/08/20/php-vs-ruby-practical-language-differences/</link>
		<comments>http://www.refreshinglyblue.com/2007/08/20/php-vs-ruby-practical-language-differences/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 05:01:08 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://refreshinglyblue.com/?p=12</guid>
		<description><![CDATA[I have been developing PHP applications professionally for over 7 years. About a year ago, I decided to try developing some Ruby on Rails applications. My main Ruby on Rails projects have included an e-commerce site QuietHeadphones.com and an online application for synchronizing medical records with USB thumb drives. Of course, I have also worked [...]]]></description>
			<content:encoded><![CDATA[<p>I have been developing <span class="caps">PHP</span> applications professionally for over 7 years. About a year ago, I decided to try developing some Ruby on Rails applications. My main Ruby on Rails projects have included an e-commerce site <a href="http://www.quietheadphones.com">QuietHeadphones.com</a> and an online application for <a href="http://www.vitalkey.com">synchronizing medical records with <span class="caps">USB</span> thumb drives</a>. Of course, I have also worked with the Ruby on Rails blogging engine Mephisto which is what runs this website. So while I have worked with <span class="caps">PHP</span> for more time than I have worked with Ruby on Rails, I have worked with Ruby on Rails long enough to have noticed some significant differences between the two languages. My comparison is going to focus on the language differences between <span class="caps">PHP</span> and Ruby and not as much on the Rails framework.</p>
<p><span id="more-12"></span></p>
<p>There are rather significant syntactical differences between <span class="caps">PHP</span> and Ruby. For example <span class="caps">PHP</span> requires semicolons at the end of lines and generally requires curly brackets to enclose blocks of code. Ruby, on the other hand, uses newline characters to denote the end of a line of code and many code constructs such as function definitions, and various loops are ended with the word &#8220;end&#8221; rather than being surrounded by curly braces. Below is an example of <span class="caps">PHP</span> vs Ruby syntax.</p>
<pre>PHP Function

function say_hello($name) {
  $out = "Hello $name";
  return $out;
}</pre>
<pre>Ruby Function

def say_hello(name)
  out = "Hello ${name}"
  return out
end</pre>
<p>In Ruby, you don&#8217;t have to specify the return line as the return value of the last evaluated line is returned automatically. There are other differences in syntax between <span class="caps">PHP</span> and Ruby and, in general, Ruby is more concise yet it is not cryptic. Another general note about <span class="caps">PHP</span> is that <span class="caps">PHP</span> has a very large number of &#8220;built-in&#8221; functions &#8211; many more than Ruby. The Rails framework adds some nice helper methods for formatting dates, numbers, currency, and the like. <span class="caps">PHP</span>, however, has a vast library of functions that can do almost anything you will need. The naming of the <span class="caps">PHP</span> functions and the order of the parameters they take are somewhat inconsistent, but the functions are there making <span class="caps">PHP</span> an amazingly complete tool set for web application development. An example of the naming inconsistency is evident in function names such as strpos() vs str_replace(). Sometimes an underscore is used to separate words and other times it&#8217;s not. While that can be annoying, it&#8217;s something you can memorize in time and it&#8217;s not a huge deal. What really matters to me is what can <span class="caps">PHP</span> do that Ruby can&#8217;t and vice versa.</p>
<p><span class="caps">PHP5</span> was first released over three years ago, July 13, 2007. Frustratingly, and for various compatibility reasons, <span class="caps">PHP5</span> is just now beginning to be an available choice on shared hosting accounts. Nevertheless, my comparison is between <span class="caps">PHP5</span> and Ruby. Both <span class="caps">PHP5</span> and Ruby have object oriented features albeit, Ruby is more sophisticated in terms of OO constructs. But I wanted to know what the real difference is between the languages. When I begin development of my next web application, what will I notice in terms of the differences between the languages.</p>
<h1>The Similarities Between <span class="caps">PHP</span> and Ruby</h1>
<p>Before getting started, I know that <span class="caps">PHP</span> and Ruby have very significant syntactic differences and different people may prefer one over the other. So it may be harder to implement certain features in one language over the other. Nevertheless both languages can do almost the same things. Both languages have try/catch/throw style exception handling. Exceptions are new to <span class="caps">PHP5</span> as <span class="caps">PHP4</span> does not have them. Both languages can be used in an object oriented way. Ruby has more powerful object oriented features but most developers probably won&#8217;t notice a difference in a normal web application. Both languages have additional functionality that can be added through libraries. In general, when developing web applications, I have not yet run into a time when I was working with one language and hit a road block where the language I was using was not capable of expressing the functionality I needed. Sometimes things are easier in one language versus the other but both <span class="caps">PHP</span> and Ruby have been able to &#8220;do&#8221; the same things.</p>
<h1>About Frameworks</h1>
<p>You can&#8217;t talk about Ruby for web development without mentioning Rails. Rails is fantastic and makes developing web applications much easier due to all of the built-in functionality. My favorite aspect of Rails is the ActiveRecord functionality. Often times, many of the objects in my applications are virtually empty except for inheriting from ActiveRecord. Validation is a breeze with Rails and is usually one line such as:</p>
<pre>validates_presence_of :attribte_name</pre>
<p>The built-in error handling with error_messages_for is very helpful. If you need more flexibility with the display of error messages, there are plugins to available for that. The ability to turn email sending on and off for testing is extremely nice. Having different configuration files for live, testing, and development environments is great.</p>
<p><span class="caps">PHP</span> has over 40 different frameworks available. I&#8217;ve spent a significant amount of time studying <span class="caps">PHP</span> frameworks. The most popular ones appear to by <a href="http://www.cakephp.org">CakePHP</a> and <a href="http://www.symfony-project.com">Symfony</a>. Both of these frameworks are essentially Rails clones. I think Symfony is the largest, and most comprehensive of the two. My favorite <span class="caps">PHP</span> Framework, howevever, is <a href="http://codeigniter.com">CodeIgniter</a>. It is a Model-View-Controller style framework and has a strong Rails feel to it, but it is much lighter weight. CodeIgniter has no code generators like Rails has. It does have an ActiveRecord style Database class but it is not as powerful as the ActiveRecord in Rails. It is, however, quite nice and very helpful &#8211; much better than nothing. CodeIgniter, as far as I know, does not have anything comparable to Migrations in Rails.</p>
<h1><span class="caps">PHP</span> Does Not Have Formal Namespaces</h1>
<p><span class="caps">PHP</span> does not officially support namespaces and Ruby does. So organizing your code in a <span class="caps">PHP</span> application is something that&#8217;s left to the developer to figure out. <span class="caps">PHP5</span> has the ability to autoload classess that are undefined. It is a very useful function and one that I have used to organize my code into name spaces. I essentially name classes with underscores separating directory names. Here is my autoload function that replaces underscores with slashes to create a path to the class files that I am using.</p>
<pre>
define("PROJECT", "/path/to/project/classes/");
define("LIBRARY", "/path/to/my/main/php5/library/classes/");

function __autoload($className) {
  $fileName = str_replace("_", DIRECTORY_SEPARATOR, $className) . ".php";
  if(preg_match("/^ProjectName_/", $className)) {
     include_once(PROJECT . $fileName);
  }
  else {
    include_once(LIBRARY . $fileName);
  }
}</pre>
<p>I have a bunch of classes that I continually reuse in my <span class="caps">PHP</span> applications. The path to the root directory of my library is stored in the <span class="caps">LIBRARY</span> constant. Any classes I write that either extend my core library or are specific to the project I am working on get stored in the location specified by the <span class="caps">PROJECT</span> constant. This has been a system that works really well for me and is a good workaround for <span class="caps">PHP</span> not having namespaces. So <span class="caps">PHP</span> not having formal namespaces has not really hindered my development efforts.</p>
<h1>Documentation</h1>
<p><span class="caps">PHP</span> kills Ruby and Rails when it comes to ease of finding, reading, and even generating documentation. The <a href="http://www.php.net/manual/en/"><span class="caps">PHP</span> website</a> has wonderful, helpful, searchable documentation. The <a href="http://api.rubyonrails.com">Rails Documentation</a> is comprehensive but much harder to navigate and has far fewer code examples. <a href="http://www.phpdoc.org/">PHPDocumentor</a> also produces much better looking documentation that is easier to navigate than <a href="http://rdoc.sourceforge.net/">RDoc</a> does.</p>
<h1>Hosting Ruby (on Rails) Is Painful And Expensive</h1>
<p>All the Ruby applications I have developed to date have used the Rails framework. So this is a comparison between hosting a <span class="caps">PHP</span> Application and a Ruby on Rails application. <span class="caps">PHP</span> has several good <span class="caps">MVC</span> style frameworks. My favorite is <a href="http://www.codeigniter.com">CodeIgniter</a> and I&#8217;ll be posting an article about it soon. Using a framework or not, <span class="caps">PHP</span> is extremely easy to host. Locate virtually any hosting company, sign up for an account and start dropping your files on the server. I can&#8217;t say the same for Ruby on Rails.</p>
<p>I started off with a DreamHost account but performance and reliability were miserable. I ended up switching to a virtual dedicated server at <a href="http://www.rimuhosting.com">Rimu Hosting</a> and have been extremely please with their service. I&#8217;m running Apache 2.0 + Mongrel + ISPConfig and it&#8217;s working out nicely. But every time I want to deploy a new application I have to&#8230;</p>
<ul>
<li>Set up a mongrel cluster</li>
<li>Configure 2 or three ports for the mongrel cluster</li>
<li>Create a map file for my random load balancer</li>
<li>Set up a way to restart the cluster if the server reboots</li>
<li>Configure Apache to forward requests to the mongrel cluster</li>
<li>Configure capistrano to deploy the application.</li>
</ul>
<p>Fortunately capistrano handles all of the annoying tedium associated with deploying the application and restarting the server. So once capistrano is setup and working, future deployments are a breeze. Also worth noting, this assumes you have your source code in Subversion. So you have to make sure that Subversion is set up and accessible over the internet to the deployment server as well as your development machine. It is good practice to have you source code in version control and you should be doing this whether the project is <span class="caps">PHP</span> or Ruby. If you are not using subversion and, therefore, not using capistrano, deploy a rails application is very time consuming and frustrating. Lastly, you need ssh access to your deployment server if you are going to be using Ruby on Rails whereas <span class="caps">PHP</span> can be deployed entirely over <span class="caps">FTP</span>.</p>
<p>To have a reasonable and reliable hosting environment for Ruby on Rails applications, you should have a virtual private server (VPS) or a dedicated server. So that will cost you at least $50 per month. You can host multiple Rails applications on the same <span class="caps">VPS</span> but the <span class="caps">RAM</span> requirements for running the mongrel clusters will quickly catch up to you. While you could host well over 50 <span class="caps">PHP</span> sites running on your <span class="caps">VPS</span> you will only be able to have a handful of Rails applications.</p>
<h1>Conclusion</h1>
<p>I suspect very few people will argue that <span class="caps">PHP</span> is a more elegant language or is more powerful than Ruby. Frankly, Ruby is probably may favorite language that I have ever worked with and I have worked with Classic <span class="caps">ASP</span>, ASP.NET, VB.NET, C#, Java, and Perl all rather extensively over the years. Ruby is both highly expressive and concise which is rare and refreshing.</p>
<p>Rails is a very comprehensive and effective web development Framework and there&#8217;s nothing exactly like it in <span class="caps">PHP</span>. You get a huge amount of functionality for free. Developing in Ruby on Rails is also a very fast process because Ruby is a very concise language requiring much less typing than any other language I&#8217;ve worked with. CodeIgniter is a really nice <span class="caps">PHP</span> framework. It will give you a great boost when developing your next <span class="caps">PHP</span> application.</p>
<p>The hosting and deployment struggles with Ruby on Rails is a major sticking point for me though. As the owner of a <a href="http://www.digitalunderware.com">web development company</a> many of our smaller clients do not have the budget for their own <span class="caps">VPS</span> account and even if they did, we don&#8217;t have the staff to manage a large number of <span class="caps">VPS</span> accounts or dedicated servers. Keeping the security updates current, managing any issues that may occur with email, and all the other headaches that go along with managing your own <span class="caps">VPS</span> or Dedicated server is more than we care to take on for the relatively small, practical dfference between <span class="caps">PHP</span> and Ruby. For large projects, it may be worth the trouble, but for small to medium sized projects, <span class="caps">PHP</span> is much easier to deploy, less expensive to host, and the language is capable of taking on everything those types of sites require. For our projects, development time with <span class="caps">PHP</span> is not noticeably longer than with Ruby on Rails. Ruby on Rails integrates a lot of things for the developer.</p>
<p>There is ActiveRecord for managing the link between models and the database, migrations for keeping development and live databases in sync, built in testing, the ajax &#8211; prototype javascript library is included, and you get a well defined file system structure. While it may not all be packaged together as well, <span class="caps">PHP</span> can do all of the above.</p>
<p>Thank you for reading this and I would love to read your comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.refreshinglyblue.com/2007/08/20/php-vs-ruby-practical-language-differences/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Setting Up Subversion And Apache for Ruby on Rails Development</title>
		<link>http://www.refreshinglyblue.com/2007/07/20/setting-up-subversion-and-apache-for-ruby-on-rails-development/</link>
		<comments>http://www.refreshinglyblue.com/2007/07/20/setting-up-subversion-and-apache-for-ruby-on-rails-development/#comments</comments>
		<pubDate>Sat, 21 Jul 2007 04:23:35 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://refreshinglyblue.com/?p=9</guid>
		<description><![CDATA[Iâ€™ve been asked several times how I have my Ruby on Rails development environment set up. The most frequently misunderstood aspect of a Rails development environment is that you do not have to have your Subversion repository physically located on the same server as your deployed application. The only requirement is that all the pieces [...]]]></description>
			<content:encoded><![CDATA[<p>Iâ€™ve been asked several times how I have my Ruby on Rails development environment set up. The most frequently misunderstood aspect of a Rails development environment is that you do not have to have your Subversion repository physically located on the same server as your deployed application. The only requirement is that all the pieces of your development environment puzzle need to be able to access one another over the internet. So, hereâ€™s how I have myself setup. It works on both linux (Ubuntu) and Windows XP.</p>
<p><span id="more-9"></span></p>
<p>My primary development platform is Ubuntu Linux but I have also set up Apache and Subversion on Windows XP. So I&#8217;ll try to make Windows related notes along the way. My deployment platform is always a Linux based system &#8211; usually Ubuntu Server. In order for Capistrano to work it&#8217;s magic in needs to make a bunch of symbolic links which is pretty much a Linux feature. While you can develop on any platform you want, make sure you are deploying to a Linux server.</p>
<h3>Setting Up Subversion and Apache</h3>
<p>This is a description of how to set up your development environment web server and Subversion repository. Again, it is not necessary to have your Subversion repository on your live server. My repository resides on my development machine. I actually have a domain name assigned to my development machine so that it can be accessed over the internet. I use <a href="http://www.zoneedit.com">zoneedit.com</a> to manage the <span class="caps">DNS</span>. It&#8217;s a pretty ugly site but it&#8217;s free, easy to use, and gets the job done. If you don&#8217;t want to bother with setting up zoneedit, simply put the IP address of your development machine in your server&#8217;s /etc/hosts file. Or, just use your IP address and forget about setting up a domain for your development machine altogether.</p>
<p>Make sure you have Subversion installed either by installing from Apt if you are on Ubuntu or downloading and installing Subversion if you are on Windows. I&#8217;m on Ubuntu so I do the following:</p>
<p class="code">sudo apt-get install subversion subversion-tools</p>
<p>Once subversion is installed, pick a place on your file system where you would like to store your repository. You might choose a location like /home/username/svn or E:\svn on Windows. You want to make sure that Apache is able to write to the folders on your file system. Change to the directory where you want your repository and then create it as follows:</p>
<p class="code">cd /home/username/svn<br />
svnadmin create application-name<br />
sudo chgrp -R www-data application-name<br />
sudo chmod -R g+w application-name</p>
<p>Now you have an empty repository. You cannot access it over the web yet as we have not yet set up Apache. You can however access the repository over your file system. So if you aren&#8217;t interested in accessing your repository through Apache, you can stop here and start using Subversion. You won&#8217;t be able to deploy your application over the internet though. So you will probably want to configure Apache to work with Subversion.</p>
<p>On Ubuntu you will need to install libapache2-svn which is the package that provides the mod_dav_svn and mod_authz_svn modules for the Apache 2.2 web server.  These modules provide Subversion&#8217;s WebDAV server backend, to serve repositories over the http and https protocols.</p>
<p class="code">sudo apt-get install libapache2-svn</p>
<p>If you are on Windows, make sure you get the apache the appropriate apache module. Then enable the following modules.</p>
<p class="code">sudo a2enmod dav<br />
sudo a2enmod dav_svn</p>
<p>If you are on windows you will probably need to enable these modules by editing your apache configuration file. You will need to add the following lines to httpd.conf</p>
<p class="code"><em>file: httpd.conf</em><br />
<br />
LoadModule dav_module modules/mod_dav.so<br />
LoadModule dav_fs_module modules/mod_dav_fs.so<br />
LoadModule dav_svn_module modules/mod_dav_svn.so</p>
<p>Next, in your Apache configuration file you need to tell Apache where your repository will be physically located. I&#8217;m using Apache 2.2 so I go into /etc/apache2/sites-available/default and setup the location for my repository as follows:</p>
<p class="code"><em>file: /etc/apache2/sites-available/default</em><br />
<br />
&lt;Location /path/to/repository&gt;<br />
  <span class="caps">DAV</span> svn<br />
  SVNPath /absolute/path/to/repository<br />
  AuthType Basic<br />
  AuthName &#8220;Subversion Repository&#8221;<br />
  AuthUserFile /absolute/path/to/password/file.txt<br />
  Require valid-user<br />
&lt;/Location&gt;</p>
<p>There are three different paths in the above configuration. The first path is the path in the Location tag. This is the path in your <span class="caps">URL</span> after your domain. For example, you might have the <span class="caps">URL</span> http://www.my-dev-site.com/svn/application-name in which case you would have  &lt;Location /svn/application-name&gt; Note, that your url path does not have to map exactly on to the path on your file system.</p>
<p>The second path is the SVNPath which is the absolute path to the location of your Subversion repository. In our example above we would use /home/username/svn/application-name</p>
<p>The third path is the absolute path to you htpasswd file. We haven&#8217;t created this yet. You may choose to put it in your home directory at /home/username/svnpasswords.txt This is the file that will house the usernames and passwords for accessing your Subversion repository through Apache. Here is how to create you password file.</p>
<p class="code">htpasswd -c /home/username/svnpasswords.txt <username></p>
<p>If you want more than one user, run the same command again but leave off the -c. If you don&#8217;t leave off the -c then a new password file will be created and all your previous entries will be lost.</p>
<p>Restart Apache and you have a functioning Subversion repository.</p>
<p>Setup the standard Subversion directories as follows:</p>
<p class="code">svn mkdir http://www.my-dev-site.com/svn/application-name/trunk -m &#8220;creating trunk&#8221;<br />
svn mkdir http://www.my-dev-site.com/svn/application-name/tags -m &#8220;creating tags&#8221;<br />
svn mkdir http://www.my-dev-site.com/svn/application-name/branches -m &#8220;creating branches&#8221;</p>
<h3>Importing Ruby on Rails Project Into Subversion</h3>
<p>Now we need to set up version control for our Ruby on Rails project. Let&#8217;s assume we&#8217;ve already got a Ruby on Rails project we want to add to Subversion. If you don&#8217;t, now is the time to create one.</p>
<p class="code">cd /home/username/rails<br />
rails application-name</p>
<p>Make sure you change directories so that you are in the root directory of your Rails application. Then checkout the trunk of your new repository.</p>
<p class="code">svn co http://www.-my-dev-site.com/svn/application-name/trunk .</p>
<p>Now add all of our project files to your working copy.</p>
<p class="code">svn add *</p>
<p>We don&#8217;t really want <span class="caps">ALL</span> of our files under version control. For example, we don&#8217;t want to store session files, log files, etc. So tell Subversion to ignore a few files.</p>
<p class="code">svn propset svn:ignore &#8221;&#42;&#8221; log/<br />
svn revert log/&#42;<br />
svn propset svn:ignore &#8221;&#42;&#8221; tmp/<br />
svn revert tmp/&#42;<br />
svn commit -m &#8220;initial project import&#8221;<br />
svn update </p>
<p>Once you are generally comfortable with setting up a project like this manually, you may want to remove some of the hassle by storing an example &#8220;starter&#8221; rails project in Subversion. When you are ready for a new project, copy the example project out of Subversion. This is an excellent tip and a clever time saver so you can <a href="http://blog.hasmanythrough.com/2006/12/28/stop-using-the-rails-command">stop using the rails command</a>.</p>
<h3>Adding Multiple Files To Subversion</h3>
<p>During the course of developing your Ruby on Rails application you will most likely have the need to add a bunch of files to version control. For example, you may have run a few generators and now you need all those files in Subversion. If you want to add all of the &#8220;unversioned&#8221; files to Subversion, here&#8217;s a command that will do that for you.</p>
<p class="code">svn st | grep &#8221;\?&#8221; | awk &#8216;{print $2}&#8217; | xargs svn add</p>
<p>This series of commands runs the status command in subversion, pipes the output to grep where we only select the lines that start with ? (indicating that the file is not in Subversion yet). The output from grep is piped to awk where we pluck out the file name of each unversioned file and pass that file name to svn add. It&#8217;s a great time saver.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.refreshinglyblue.com/2007/07/20/setting-up-subversion-and-apache-for-ruby-on-rails-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails + SSL + ISPConfig + Apache 2.0 + Mongrel</title>
		<link>http://www.refreshinglyblue.com/2007/06/13/ruby-on-rails-ssl-ispconfig-apache-mongrel/</link>
		<comments>http://www.refreshinglyblue.com/2007/06/13/ruby-on-rails-ssl-ispconfig-apache-mongrel/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 03:43:57 +0000</pubDate>
		<dc:creator>Lee</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://refreshinglyblue.com/?p=8</guid>
		<description><![CDATA[If you are using ISPConfig to manage the virtual hosts on your web server, you will notice that there is no way to separate SSL vs non-SSL Apache directives using the standard web interface. This is a problem if you are writing Ruby on Rails applications and proxying requests through Apache to a Mongrel cluster [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using ISPConfig to manage the virtual hosts on your web server, you will notice that there is no way to separate SSL vs non-SSL Apache directives using the standard web interface. This is a problem if you are writing Ruby on Rails applications and proxying requests through Apache to a Mongrel cluster because Mongrel won&#8217;t know what type of requests it is receiving. Being behind the proxy, Mongrel doesn&#8217;t know if the original requests are coming via HTTP or HTTPS. The solution is to add RequestHeader set X_FORWARDED_PROTO &#8216;https&#8217; as a line in your Apache virtual host configuration for the SSL virtual host. I will tell you how to get ISPConfig to handle that for you. I will also show how to get GoDaddy.com ssl certificates working and how our Apache 2.0 randomized proxy balancer works.</p>
<p><span id="more-8"></span></p>
<p>We are running Apache 2.0 and proxying to a Mongrel cluster for our latest e-commerce website <a href="http://www.quietheadphones.com">QuietHeadphones.com</a> which is scheduled to be launched at the end of June. Being an e-commerce site we needed to put the checkout functionality behind SSL. Since Apache is handling both the HTTPS/SSLfunctionality as well as the standard HTTP requests and proxying everything to the Mongrel cluster, the Mongrel cluster doesn&#8217;t know which requests are HTTPS and which are HTTP. To tell Rails which requests are HTTPS requests you can set up an environment variable in the Apache virtual host configuration in the httpd.conf file. The environement variable is: </p>
<p class="code">RequestHeader set X_FORWARDED_PROTO &#8216;https&#8217;</p>
<p>In Rails, request.rb checks for that variable and pleasantly handles everything else for you.</p>
<p>Now if you are using ISPConfig to manage the virtual hosts on your web server, you will notice that there is no way to separate SSL vs non-SSL Apache directives using the web interface. Since most of our sites are Ruby on Rails sites and since the RequestHeader variable doesn&#8217;t hurt anything if you aren&#8217;t using rails, I revised the source code of ISPConfig to always include the RequestHeader set X_FORWARDED_PROTO line in all of the SSL virtual host configurations. That way, anytime you set up a site in ISPConfig and select the SSL option, ISPConfig faithfully inserts the RequestHeader line so that Mongrel knows what sort of requests it is getting.</p>
<p>To make this revision to ISPConfig, open up config.lib.php then edit the SSL-Web section at approximately line 1521 by adding RequestHeader set X_FORWARDED_PROTO &#8216;https&#8217;</p>
<p class="code">file: /root/ispconfig/scripts/lib/config.lib.php<br />
<br />
RequestHeader set X_FORWARDED_PROTO &#8216;https&#8217;
</p>
<p>Once that is in place, all HTTPS requests will have that request header variable set and regular HTTP requests will not. Then you can use the standard web interface to configure the rest of the Apache directives for your Ruby on Rails application and the Mongrel cluster. Here&#8217;s an example of what the Apache Directives text box may look like in ISPConfig.</p>
<p class="code">
&lt;Proxy *&gt;<br />
  Order allow,deny<br />
  Allow from all<br />
&lt;/Proxy&gt;<br />
<br />
ProxyRequests Off<br />
ProxyPassReverse / http://www.mydomain.com:9001/<br />
ProxyPassReverse / http://www.mydomain.com:9002/<br />
ProxyPassReverse / http://www.mydomain.com:9003/<br />
ProxyPreserveHost On<br />
RewriteEngine On<br />
RewriteMap  servers rnd:/var/www/webX/rails/map.txt<br />
RewriteRule ^/(images|stylesheets|javascripts)/?(.*) $0 [L]<br />
RewriteRule ^/(.*)$ http://www.mydomain.com:${servers:ports}/$1 [P,L]<br />
Alias /images /var/www/webX/web/images<br />
Alias /stylesheets /var/www/webX/web/stylesheets<br />
Alias /javascripts /var/www/webX/web/javascripts<br />
SSLCertificateChainFile /var/www/webX/ssl/gd_intermediate_bundle.crt
</p>
<p>There are a couple things to note in this example. At the time of this writing, we are using Apache 2.0 and, therefore, don&#8217;t have access to the mod_proxy_balancer that many people are enjoying with Apache 2.2. Nevertheless, we wanted to run a Mongrel cluster so we are using a randomized proxy balancer by taking advantage of the RewriteMap feature of Apache 2.0. We created a text file that contains the port numbers that each of our Mongrel instances are using separated by pipes as follows:</p>
<p class="code">file: map.txt<br />
<br />
ports 9001|9002|9003
</p>
<p>Then on each request, Apache randomly selects on of the three ports from the map.txt file and rewrites the request for one of our mongrel instances.</p>
<p class="code">
RewriteRule ^/(.*)$ http://www.mydomain.com:${servers:ports}/$1 [P,L]
</p>
<p>Lastly, if you buy an SSL certificate from godaddy.com, you will need to add the SSLCertificateChainFile directive to your Apache configuration. Otherwise, most &#8211; perhaps all &#8211; browsers will complain about the ssl certificate not being trusted. Once you know about that, it&#8217;s an easy adjustment to make. Simply give Apache the path to the gd_intermediate_bundle.crt that you will get when you buy your ssl certificate at GoDaddy.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.refreshinglyblue.com/2007/06/13/ruby-on-rails-ssl-ispconfig-apache-mongrel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
