<?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>Cristian Livadaru's blog &#187; ruby on rails</title>
	<atom:link href="http://cristian.livadaru.net/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://cristian.livadaru.net</link>
	<description>... think again ...</description>
	<lastBuildDate>Sat, 28 Aug 2010 19:47:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Distributing Rails Applications, with migrations</title>
		<link>http://cristian.livadaru.net/2009/02/22/distributing-rails-applications-with-migrations/</link>
		<comments>http://cristian.livadaru.net/2009/02/22/distributing-rails-applications-with-migrations/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 01:38:10 +0000</pubDate>
		<dc:creator>Cristian Livadaru</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[distribute]]></category>
		<category><![CDATA[exe]]></category>

		<guid isPermaLink="false">http://cristian.livadaru.net/?p=613</guid>
		<description><![CDATA[Creating a executable file (.exe for windows for example) from a Ruby on Rails application isn&#8217;t something really new. There enough informations about that on the net, the best one can be found here. Well, then why am I writing this blog? Well the manual from Erik Veenstra ist quite good, but what I didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a executable file (.exe for windows for example) from a Ruby on Rails application isn&#8217;t something really new. There enough informations about that on the net, the best one can be found <a href="http://www.erikveen.dds.nl/distributingrubyapplications/rails.html">here</a>.<br />
Well, then why am I writing this blog? Well the manual from Erik Veenstra ist quite good, but what I didn&#8217;t find there anywhere was how to get the migrations done! I want to be able to give this .exe file to someone (or actually I was forced to do it this way) and they should be able to use the application, but when you keep updates in mind then you must have some way to also get migrations working. </p>
<p>I will be repeating some steps that are already mentioned in the &#8220;<a href="http://www.erikveen.dds.nl/distributingrubyapplications/rails.html">Distributing Rails Applications</a>&#8221; tutorial.<br />
First add this to the top of your environment.rb, this is a bit different then mentioned in the tutorial. Basically it should be working as mentioned in the tutorial, but in the last two days I was trying to solve this problem until late in the night and can&#8217;t really remember why I changed it <img src='http://cristian.livadaru.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> Rails
  <span style="color:#9966CC; font-weight:bold;">class</span> Configuration
    <span style="color:#9966CC; font-weight:bold;">def</span> database_configuration
      conf = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">ERB</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>database_configuration_file<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">result</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">defined</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>TAR2RUBYSCRIPT<span style="color:#006600; font-weight:bold;">&#41;</span>
        conf.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>k, v<span style="color:#006600; font-weight:bold;">|</span>
          <span style="color:#9966CC; font-weight:bold;">if</span> v<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;adapter&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> =~ <span style="color:#006600; font-weight:bold;">/</span>^sqlite3<span style="color:#006600; font-weight:bold;">/</span>
            v<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;database&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = oldlocation<span style="color:#006600; font-weight:bold;">&#40;</span>v<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;database&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> v.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;database&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
            v<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;dbfile&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>   = oldlocation<span style="color:#006600; font-weight:bold;">&#40;</span>v<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;dbfile&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>   <span style="color:#9966CC; font-weight:bold;">if</span> v.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;dbfile&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
          <span style="color:#9966CC; font-weight:bold;">end</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#CC00FF; font-weight:bold;">YAML</span>::<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">ERB</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">IO</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span>database_configuration_file<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">result</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Create a init.rn in the root of your application folder, you can remove the three &#8220;puts&#8221; lines, just added them for debug purposes.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">at_exit</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;irb&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;drb/acl&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;sqlite3&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Running as an RBA.&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">defined</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>TAR2RUBYSCRIPT<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Runing from: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> oldlocation
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Runing in: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> newlocation
&nbsp;
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">&quot;mig.rb&quot;</span>
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">&quot;script/server&quot;</span></pre></div></div>

<p>As you can see there is a new &#8220;load&#8221; line which load mig.rb before starting the server. Here is where the magic happens.<br />
Actually the mig.rb is nothing but a copy of the rake script with a extra line.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rake'</span>
&nbsp;
version = <span style="color:#996600;">&quot;&gt;= 0&quot;</span>
&nbsp;
ARGV<span style="color:#006600; font-weight:bold;">&lt;&lt;</span><span style="color:#996600;">&quot;db:migrate&quot;</span>
&nbsp;
gem <span style="color:#996600;">'rake'</span>, version
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'rake'</span></pre></div></div>

<p>So what happens is that tar2rubyscript executes init.rb on startup, then the mig.rb is called which always does a rake db:migrate. This is done but manually adding &#8220;db:migrate&#8221; to ARGV, this has to be done so the script can be started with &#8220;load&#8221;, starting the script with a system command won&#8217;t work!<br />
This is because the environment set up by tar2rubyscript will be missing and your migrations just won&#8217;t work.</p>
<p>Thats all! Incredible that for this answer I spend 2 long long nights. But now it works as it should, when starting it without tar2rubyscript it work&#8217;s as usual and with tar2rubyscript it works also great and I can have migrations when I send out new software versions. <br />
The idea is that the same application is intended to run in two different environments, one being a usual ruby on rails environment on Linux with a MySQL Database and the other being sent out via CD and it must run on windows.<br />
I could have made complete installer to install Ruby, Rubygems, SQLite, the Gems I need &#8230; and much more. This way it is much much easier and nobody has to install anything, just click the exe, open the browser and start working.</p>
]]></content:encoded>
			<wfw:commentRss>http://cristian.livadaru.net/2009/02/22/distributing-rails-applications-with-migrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[HowTo] Installing Ruby Enterprise Edition and Passenger on Debian Etch</title>
		<link>http://cristian.livadaru.net/2009/01/12/howto-installing-ruby-enterprise-edition-and-passenger-on-debian-etch/</link>
		<comments>http://cristian.livadaru.net/2009/01/12/howto-installing-ruby-enterprise-edition-and-passenger-on-debian-etch/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 14:22:46 +0000</pubDate>
		<dc:creator>Cristian Livadaru</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[debuan]]></category>

		<guid isPermaLink="false">http://cristian.livadaru.net/?p=593</guid>
		<description><![CDATA[Install some stuff we will need apt-get install build-essential apache2 ruby1.8 zlib1g-dev libssl-dev mysql-server mysql-common libmysqlclient15-dev libmysqlclient15off apache2-prefork-dev Create a link for ruby else the installer won&#8217;t work ln -s /usr/bin/ruby1.8 /usr/bin/ruby get Ruby Enterprise edition (http://www.rubyenterpriseedition.com/download.html) tar xzvf ruby-enterprise-X.X.X.tar.gz ./ruby-enterprise-X.X.X/installer Delete the Ruby link and create new links rm /usr/bin/ruby ln -s /opt/ruby-enterprise-1.8.6-20081215/bin/rake /usr/bin/rake [...]]]></description>
			<content:encoded><![CDATA[<p>Install some stuff we will need</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> build-essential apache2 ruby1.8 zlib1g-dev libssl-dev mysql-server mysql-common libmysqlclient15-dev libmysqlclient15off apache2-prefork-dev</pre></div></div>

<p>Create a link for ruby else the installer won&#8217;t work</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby1.8 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby</pre></div></div>

<p>get Ruby Enterprise edition (http://www.rubyenterpriseedition.com/download.html)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf ruby-enterprise-X.X.X.tar.gz
.<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-X.X.X<span style="color: #000000; font-weight: bold;">/</span>installer</pre></div></div>

<p>Delete the Ruby link and create new links</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rake <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rake
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem 
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rails <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rails
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby</pre></div></div>

<p>Install Passenger</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>passenger-install-apache2-module</pre></div></div>

<p>if you have this error</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>passenger-2.0.6
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby <span style="color: #660033;">-S</span> rake clean apache2
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory <span style="color: #660033;">--</span> rake <span style="color: #7a0874; font-weight: bold;">&#40;</span>LoadError<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>then it looks like the Rake GEM was not installed, just install it now. and don&#8217;t forget to create the symlink in /usr/bin !</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gem <span style="color: #c20cb9; font-weight: bold;">install</span> rake</pre></div></div>

<p>Add this to /etc/apache2/apache2.conf</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">LoadModule</span> passenger_module /opt/ruby-enterprise-1.8.6-<span style="color: #ff0000;">20081215</span>/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby-enterprise-1.8.6-<span style="color: #ff0000;">20081215</span>/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-2.0.6
PassengerRuby /opt/ruby-enterprise-1.8.6-<span style="color: #ff0000;">20081215</span>/bin/ruby</pre></div></div>

<p>That&#8217;s it ! Now you can configure your vhosts.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> 192.168.0.1:<span style="color: #ff0000;">80</span>&gt;
  <span style="color: #00007f;">ServerName</span> foo.com
  <span style="color: #00007f;">DocumentRoot</span> /var/rails/
&nbsp;
  RailsBaseURI /project1
  RailsBaseURI /project2
  RailsBaseURI /project3
&nbsp;
  <span style="color: #00007f;">Alias</span> /docs <span style="color: #7f007f;">&quot;/opt/ruby-enterprise-1.8.6-20081215/lib/ruby/gems/1.8/gems/passenger-2.0.6/doc/Users guide.html&quot;</span>
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<p>An finaly, the capistrano config in deploy.rb</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;project1&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:repository</span>,  <span style="color:#996600;">&quot;https://svn.foo.com/project1&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">'root'</span>
set <span style="color:#ff3333; font-weight:bold;">:use_sudo</span>, <span style="color:#0000FF; font-weight:bold;">false</span>
<span style="color:#008000; font-style:italic;"># If you aren't deploying to /u/apps/#{application} on the target</span>
<span style="color:#008000; font-style:italic;"># servers (which is the default), you can specify the actual location</span>
<span style="color:#008000; font-style:italic;"># via the :deploy_to variable:</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/var/rails/#{application}&quot;</span>
&nbsp;
after <span style="color:#996600;">&quot;deploy:update_code&quot;</span>, <span style="color:#996600;">&quot;deploy:chown&quot;</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;foo.com&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;foo.com&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  <span style="color:#996600;">&quot;foo.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Change owner&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:chown</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;chown www-data:www-data -R #{latest_release}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  desc <span style="color:#996600;">&quot;Restart Application&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:app</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;touch #{current_path}/tmp/restart.txt&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>in case you have this error:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">script<span style="color: #000000; font-weight: bold;">/</span>console production
Loading production environment <span style="color: #7a0874; font-weight: bold;">&#40;</span>Rails 2.1.0<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>irb<span style="color: #000000; font-weight: bold;">/</span>completion.rb:<span style="color: #000000;">10</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>require<span style="color: #ff0000;">': no such file to load -- readline (LoadError)
        from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/completion.rb:10
        from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/init.rb:252:in `require'</span>
        from <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>irb<span style="color: #000000; font-weight: bold;">/</span>init.rb:<span style="color: #000000;">252</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>load_modules<span style="color: #ff0000;">'
        from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/init.rb:250:in `each'</span>
        from <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>irb<span style="color: #000000; font-weight: bold;">/</span>init.rb:<span style="color: #000000;">250</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>load_modules<span style="color: #ff0000;">'
        from /opt/ruby-enterprise-1.8.6-20081215/lib/ruby/1.8/irb/init.rb:21:in `setup'</span>
        from <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>irb.rb:<span style="color: #000000;">54</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>start<span style="color: #ff0000;">'
        from /usr/bin/irb:13</span></pre></div></div>

<p>Then some things where missing during install. Let&#8217;s install that and compile readling.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>ruby-enterprise-1.8.6-<span style="color: #000000;">20081215</span><span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span>ext<span style="color: #000000; font-weight: bold;">/</span>readline
&nbsp;
ruby extconf.rb
checking <span style="color: #000000; font-weight: bold;">for</span> tgetnum<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">in</span> -lncurses... no
checking <span style="color: #000000; font-weight: bold;">for</span> tgetnum<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">in</span> -ltermcap... no
checking <span style="color: #000000; font-weight: bold;">for</span> tgetnum<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">in</span> -lcurses... no
checking <span style="color: #000000; font-weight: bold;">for</span> readline<span style="color: #000000; font-weight: bold;">/</span>readline.h... no
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libncurses5-dev libreadline5-dev</pre></div></div>

<p>Check once again if everything is installed</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ruby extconf.rb
.
.
creating Makefile</pre></div></div>

<p>and now compile</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cristian.livadaru.net/2009/01/12/howto-installing-ruby-enterprise-edition-and-passenger-on-debian-etch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AJAX validation on Rails</title>
		<link>http://cristian.livadaru.net/2009/01/05/ajax-validation-on-rails/</link>
		<comments>http://cristian.livadaru.net/2009/01/05/ajax-validation-on-rails/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 09:27:13 +0000</pubDate>
		<dc:creator>Cristian Livadaru</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://cristian.livadaru.net/?p=584</guid>
		<description><![CDATA[I had a ajax form to add languages in the system in one of my projects. A pretty simple form with just one text field. The problem I had was with validations and display the error message if something goes wrong. After search the net for a while I came across this blog from bigsmoke [...]]]></description>
			<content:encoded><![CDATA[<p>I had a ajax form to add languages in the system in one of my projects. A pretty simple form with just one text field. The problem I had was with validations and display the error message if something goes wrong.<br />
After search the net for a while I came across this <a href="http://www.bigsmoke.us/ajax-validation-on-rails/" target="_blank">blog from bigsmoke</a> which could solve my issues, but after looking a bit it kind of looks a bit complicated and I wanted something more simple.<br />
I took some ideas from <a href="http://www.bigsmoke.us/" target="_blank">bigsmoke </a>and did my own thing.</p>
<p>So here is my implementation of Ajax validation on Rails:</p>
<p>My controller has a &#8220;new&#8221; action which looks like this</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> new
  <span style="color:#0066ff; font-weight:bold;">@language</span> = Language.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:language</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@language</span>.<span style="color:#9900CC;">save</span>
    <span style="color:#0066ff; font-weight:bold;">@language</span>.<span style="color:#9900CC;">reload</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#9966CC; font-weight:bold;">if</span> request.<span style="color:#9900CC;">xhr</span>?
  <span style="color:#9966CC; font-weight:bold;">else</span>
    render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'error'</span>, <span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">444</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The view where the languages are displayed I have added a hidden div which will display the error message if present</p>
<p>Here is where the most stuff happens, in the _error.rjs</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">page.<span style="color:#9900CC;">replace_html</span> <span style="color:#996600;">'errors'</span>, <span style="color:#996600;">&quot;Language could not be created. Reason: #{@language.errors.full_messages}&quot;</span>
page.<span style="color:#9900CC;">delay</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  page.<span style="color:#9900CC;">visual_effect</span> <span style="color:#ff3333; font-weight:bold;">:fade</span>, <span style="color:#996600;">'errors'</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
page<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;errors&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">toggle</span></pre></div></div>

<p>This replaces the errors div with a message and the errors returned from the validation, it starts a fade with a delay so that the error message will disappear after a while and finally, the div is set to visible.</p>
<p>That&#8217;s it! It really is that simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://cristian.livadaru.net/2009/01/05/ajax-validation-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

