<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/"
>

<channel>
	<title>alanmaciel.net -- coder for hire</title>
	<atom:link href="http://www.alanmaciel.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.alanmaciel.net</link>
	<description>From coder to Craftmanship</description>
	<lastBuildDate>Fri, 23 Nov 2012 20:24:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
<!-- podcast_generator="Blubrry PowerPress/4.0.4" -->
	<itunes:summary>From coder to Craftmanship</itunes:summary>
	<itunes:author>alanmaciel.net -- coder for hire</itunes:author>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://www.alanmaciel.net/wp-content/plugins/powerpress/itunes_default.jpg" />
	<itunes:subtitle>From coder to Craftmanship</itunes:subtitle>
	<image>
		<title>alanmaciel.net -- coder for hire</title>
		<url>http://www.alanmaciel.net/wp-content/plugins/powerpress/rss_default.jpg</url>
		<link>http://www.alanmaciel.net</link>
	</image>
		<item>
		<title>WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.8</title>
		<link>http://www.alanmaciel.net/?p=104&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=warning-nokogiri-was-built-against-libxml-version-2-8-0-but-has-dynamically-loaded-2-7-8</link>
		<comments>http://www.alanmaciel.net/?p=104#comments</comments>
		<pubDate>Fri, 23 Nov 2012 03:32:14 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=104</guid>
		<description><![CDATA[I did a brew uninstall libxml2 it was the version libxml2 2.8.0 and i guess my os x has libxml2 version 2.7.8 pre-installed then i did gem uninstall nokogiri and then gem install nokogiri Warning is gone now. But it&#8217;s libxml2 version 2.7.8 and not the latest. So, I appreciate, if you suggest some solution that work with latest version [...]]]></description>
			<content:encoded><![CDATA[<p>I did a <code>brew uninstall libxml2</code> it was the version libxml2 2.8.0 and i guess my os x has libxml2 version 2.7.8 pre-installed</p>
<p>then i did <code>gem uninstall nokogiri</code> and then <code>gem install nokogiri</code></p>
<p>Warning is gone now. But it&#8217;s libxml2 version 2.7.8 and not the latest. So, I appreciate, if you suggest some solution that work with latest version of libxml2.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>UPDATED***</p>
<p>Moved gem &#8216;nokogiri&#8217; in the Gemfile to the top (just below gem &#8216;rails&#8217;) then:</p>
<pre><code>brew uninstall libxml2 gem uninstall nokogiri gem install nokogiri </code></pre>
<p>If that doesn&#8217;t work you could try:</p>
<pre><code>brew uninstall libxml2 </code></pre>
<pre><code>gem uninstall nokogiri </code></pre>
<pre><code>gem install nokogiri </code></pre>
<pre>brew install libxml2</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=104</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fútbol Con Sentido &#8211; Apertura 2012</title>
		<link>http://www.alanmaciel.net/?p=100&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=futbol-con-sentido-apertura-2012</link>
		<comments>http://www.alanmaciel.net/?p=100#comments</comments>
		<pubDate>Thu, 27 Sep 2012 18:41:01 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=100</guid>
		<description><![CDATA[Interesante plática con César Martinez y David Maiz acerca de la Apertura 2012, Fútbol Con Sentido.]]></description>
			<content:encoded><![CDATA[<p>Interesante plática con César Martinez y David Maiz acerca de la Apertura 2012, Fútbol Con Sentido.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=100</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://cdn.fut11.com/images/FCS-Sep27-2012-mp.mp3" length="21130022" type="audio/mpeg" />
		<itunes:subtitle>Interesante plática con César Martinez y David Maiz acerca de la Apertura 2012, Fútbol Con Sentido.</itunes:subtitle>
		<itunes:summary>Interesante plática con César Martinez y David Maiz acerca de la Apertura 2012, Fútbol Con Sentido.</itunes:summary>
		<itunes:author>alanmaciel.net -- coder for hire</itunes:author>
		<itunes:explicit>no</itunes:explicit>
		<itunes:duration>43:57</itunes:duration>
	</item>
		<item>
		<title>RMagick working with Mountain Lion</title>
		<link>http://www.alanmaciel.net/?p=94&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rmagick-working-with-mountain-lion</link>
		<comments>http://www.alanmaciel.net/?p=94#comments</comments>
		<pubDate>Fri, 31 Aug 2012 19:19:20 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[howtos]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=94</guid>
		<description><![CDATA[brew update brew tap homebrew/dupes brew install apple-gcc42 Installed XQuartz 2.7.2 (http://xquartz.macosforge.org/landing) Fixed any errors reported by brew doctor Ran this in terminal:gem uninstall rmagick brew uninstall imagemagick brew install --fresh imagemagick gem install rmagick if it fails  Might want to mention that second step, because your first step alone didn't work for me (though I [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li><code>brew update</code><br />
<code>brew tap homebrew/dupes</code><br />
<code>brew install apple-gcc42</code></li>
<li>Installed XQuartz 2.7.2 (<a href="http://xquartz.macosforge.org/landing" target="_blank">http://xquartz.macosforge.org/landing</a>)</li>
<li>Fixed any errors reported by <em>brew doctor</em></li>
<li>Ran this in terminal:<code>gem uninstall rmagick</code><br />
<code>brew uninstall imagemagick</code><br />
<code>brew install --fresh imagemagick</code><br />
<code>gem install rmagick</code></p>
<p><code><br />
</code></p>
<p><code>if it fails </code></p>
<p><code><br />
</code></p>
<p><code>Might want to mention that second step, because your first step alone didn't work for me (though I was using tmux): <code>ln -s /usr/local/include/ImageMagick/wand /usr/local/include/wand &amp;&amp; ln -s /usr/local/include/ImageMagick/magick /usr/local/include/magick</code><br />
</code></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=94</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating PDFs from Ruby on Rails</title>
		<link>http://www.alanmaciel.net/?p=90&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=generating-pdfs-from-ruby-on-rails</link>
		<comments>http://www.alanmaciel.net/?p=90#comments</comments>
		<pubDate>Sat, 24 Sep 2011 04:31:50 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=90</guid>
		<description><![CDATA[Generating PDFs from Ruby on Rails Posted on March 3, 2010 by andy The problem Ruby on Rails provides various helpers for generating dynamic web content but sometimes you need documents that users can easily store and share between them. The ubiquitous file format for this is Adobe PDF nowadays. The common solution fro this problem is [...]]]></description>
			<content:encoded><![CDATA[<h1>Generating PDFs from Ruby on <strong>Rails</strong></h1>
<div>Posted on <a href="http://snikt.net/index.php/2010/03/03/generating-pdfs-from-ruby-on-rails" rel="bookmark"><time datetime="2010-03-03T14:25:45+00:00" pubdate="">March 3, 2010</time> by </a><a title="View all posts by andy" href="http://snikt.net/index.php/author/andy">andy</a></div>
<div>
<h2>The problem</h2>
<p><a href="http://rubyonrails.org/">Ruby on <strong>Rails</strong></a> provides various helpers for generating dynamic web content but sometimes you need documents that users can easily store and share between them. The ubiquitous file format for this is <a href="http://en.wikipedia.org/wiki/Adobe_PDF">Adobe <strong>PDF</strong></a> nowadays.</p>
<p>The common solution fro this problem is Prawn [<a href="http://wiki.github.com/sandal/prawn/">github</a>, <a href="http://railscasts.com/episodes/153-pdfs-with-prawn">introduction</a>]. Alas it requires a custom DSL for document description, no existing <strong>Rails</strong> views or partials can be reused. An alternative is <a href="http://www.princexml.com/">princeXML</a> which transforms HTML/CSS into <strong>pdf</strong> through an external binary. This would allow reuse of existing templates and knowledge (think CSS designers) but has the downside of its price tag of $3800.</p>
<h2>The solution</h2>
<p>Enters <a href="http://github.com/mileszs/wicked_pdf">wicked_pdf</a>: it utilizes <a href="http://code.google.com/p/wkhtmltopdf/">wkhtmltopdf</a> to create a <strong>PDF</strong> document from a <strong>Rails</strong> HTML template. HTML rendering is done through the well-known webkit-engine. This allows developers to do PDFs in the right way™: define the document’s structure through a simple HTML document and theme them through CSS. You’ll get the automatic benefit of themability: exchange the CSS and you have another format. There are also lots of CSS artists out there that can supply you with different designs.</p>
<p>&nbsp;</p>
<p>I’ve used this solution with a test Ruby on <strong>Rails</strong> 3.0-beta application, the steps involved were:</p>
<h3>Install <em>wkhtmltopdf:</em></h3>
<p><strong>This program will convert the HTML into the <strong>PDF</strong> format. To make it work you’ll need at least version 0.9 which isn’t installed in Ubuntu 9.10 by default. Just download the <a href="http://code.google.com/p/wkhtmltopdf/downloads/list">static compiled version</a> from the <a href="http://code.google.com/p/wkhtmltopdf/downloads/list">wkhtmltopdf website</a> and place it under <em>/usr/local/bin</em>. </strong></p>
<h3>Install the wicked_pdf plugin:</h3>
<p>Just install it in the usual <strong>Rails</strong> way:</p>
<pre>git submodule add git://github.com/mileszs/wicked_pdf.git vendor/plugins/wicked_pdf</pre>
<p>Additionally a sample configuration file is needed. You could use the plugin’s generator script for it but alas this didn’t work for me with <strong>Rails</strong> 3.0. Let’s just copy it form the plugin’s directory into config/initializers.</p>
<pre>$ cp vendor/plugins/wicked_pdf/generators/wicked_pdf/templates/wicked_pdf.rb config/initializers</pre>
<p>and alter the wkhtmltopdf path within it:</p>
<pre>  WICKED_PDF = {
       :exe_path =&gt; '/usr/local/bin/wkhtmltopdf-amd64'
  }</pre>
<h3>Add <strong>pdf</strong> instructions to your controller..</h3>
<p>For example I’m using the <em>invoice#index</em> action to render a simple <strong>PDF</strong> document.</p>
<pre>  format.<strong>pdf</strong> do
          @example_text = "some text"
          render :<strong>pdf</strong> =&gt; "file_name",
                 :template =&gt; 'offers/show.<strong>pdf</strong>.erb',
                 :layout =&gt; '<strong>pdf</strong>',
                 :footer =&gt; {
                    :center =&gt; "Center",
                    :left =&gt; "Left",
                    :right =&gt; "Right"
                 }
  end</pre>
<p>We are rendering the view with a predefined footer containing some sample “center”, “left” and “right” strings. The <em>render :<strong>pdf</strong></em> call has various options which can be seen on the wicked_pdf homepage.</p>
<h3>.. and create <strong>PDF</strong> templates</h3>
<p>The other half of the <strong>PDF</strong> templates is the view code consisting of a special layout and template for <strong>pdf</strong> generation.</p>
<p>The layout (<em>app/views/layouts/<strong>pdf</strong>.html.erb</em>) resembles a normal Ruby on <strong>Rails</strong> layout file:</p>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
    &lt;%= wicked_pdf_stylesheet_link_tag "<strong>pdf</strong>" %&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id="content"&gt;
      &lt;%= yield %&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>The view code should not be too surprising, just place it under <em>app/views/offers/index.<strong>pdf</strong>.erb</em> :</p>
<pre>&lt;div id="someid"&gt;&lt;%= @example_text %&gt;&lt;/div&gt;</pre>
<p>Lets also create a simple CSS file (<em>public/stylesheets/<strong>pdf</strong>.css</em>):</p>
<pre>#someid {
  margin-left: 430px;
  display: float;
  height: 150px;
  background-color: green;
  width: 250px;
}</pre>
<p>&nbsp;</p>
<p>This is the whole rendering code.</p>
<h3>Reference the <strong>PDF</strong> view and download it</h3>
<p>We still need a reference to the newly created rendernig link, we can easily create this through:</p>
<pre>link_to 'Create <strong>PDF</strong> document', invoice_path(@invoice, :format =&gt; :<strong>pdf</strong>)</pre>
<p>When the link is clicked a <strong>pdf</strong> document will be generated and downloaded.</p>
<h2>Conclusion</h2>
<p>wicked_pdf allows easy <strong>pdf</strong> generation in a very Ruby on <strong>Rails</strong>’ way. It’s free, it works and is easy to employ..</p>
<p>..but not everything is perfect within the wicked_pdf world, especially error handlnig is lacking sometimes. When you’ve debugging initial problems you can expect the only error feedback to be a HTTP return code of 406. Just start with limited controller (rendering) options and double check that you’ve referenced the right view and layout paths and you should be fine.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=90</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Phusion Passenger to Deploy a Rails Application on Apache</title>
		<link>http://www.alanmaciel.net/?p=84&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-phusion-passenger-to-deploy-a-rails-application-on-apache</link>
		<comments>http://www.alanmaciel.net/?p=84#comments</comments>
		<pubDate>Wed, 14 Sep 2011 19:07:14 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=84</guid>
		<description><![CDATA[In this tutorial, I will explain how to set up Phusion Passenger, configure Apache, and deploy multiple Rails applications on Apache. I assume you are running a Linux box, as most modern-day hosting solutions include a VPS (virtual private server) instance or a dedicated server instance, and you should be comfortable with the basics of [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, I will explain how to set up Phusion Passenger, configure Apache, and deploy multiple Rails applications on Apache. I assume you are running a Linux box, as most modern-day hosting solutions include a VPS (virtual private server) instance or a dedicated server instance, and you should be comfortable with the basics of using a Linux command line.</p>
<h3>Setting Up Phusion Passenger</h3>
<p>Phusion Passenger uses <em>mod_rails</em>, a module of Apache, to serve Rails applications via the Apache2 Web server. The first prerequisite for setting up the Passenger module is to install Apache2.</p>
<p>Phusion Passenger can be installed in three different ways. The first way is to install a typical gem like this:</p>
<pre>saurabh@saurabh-laptop:~$ sudo gem install passenger
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed fastthread-1.0.7
Successfully installed passenger-2.2.11
2 gems installed</pre>
<p>When the gem is installed, you can install the Apache2 module for Rails. A few other dependencies are required in order to install the Apache2 module. They are <em>apache2-prefork-dev</em> (The Apache2 Development headers), <em>libapr1-dev</em> (Apache Portable Runtime), and <em>libaprutil1-dev</em> (Apache Portable Runtime Utility). Make sure you install all of these as follows before you continue.</p>
<pre>saurabh@saurabh-laptop:~$ passenger-install-apache2-module</pre>
<p>You will be guided through some installation steps as shown in Figure 1-3:</p>
<p><a href="http://www.wdvl.com/Authoring/ror/Passenger/PhusionFig1.png" target="newFrame"><br />
<img src="http://www.wdvl.com/Authoring/ror/Passenger/PhusionFig1.png" alt="Welcome to Phusion Passenger Apache 2 Module Installer" width="400" height="300" /><br />
<span style="font-size: xx-small;"><em>Click here for larger image</em></span></a><br />
<span style="font-size: x-small;"><strong>Figure 1.</strong> Welcome to Phusion Passenger Apache 2 Module Installer</span></p>
<p><a href="http://www.wdvl.com/Authoring/ror/Passenger/PhusionFig2.png" target="newFrame"><br />
<img src="http://www.wdvl.com/Authoring/ror/Passenger/PhusionFig2.png" alt="Phusion Passenger Apache 2 Module Installer Checking for Required Software" width="400" height="300" /><br />
<span style="font-size: xx-small;"><em>Click here for larger image</em></span></a><br />
<span style="font-size: x-small;"><strong>Figure 2.</strong> Checking for Required Software</span></p>
<p><a href="http://www.wdvl.com/Authoring/ror/Passenger/PhusionFig3.png" target="newFrame"><br />
<img src="http://www.wdvl.com/Authoring/ror/Passenger/PhusionFig3.png" alt="Phusion Passenger Apache 2 Module Successfully Installed" width="400" height="300" /><br />
<span style="font-size: xx-small;"><em>Click here for larger image</em></span></a><br />
<span style="font-size: x-small;"><strong>Figure 3.</strong> Apache 2 Module Was Successfully Installed</span></p>
<p>The second way to install Passenger is from source:</p>
<ol>
<li>Download the <a href="http://rubyforge.org/frs/?group_id=5873" target="newFrame">Passenger source from RubyForge</a> and download it to a folder where it will permanently reside, as follows:
<pre>saurabh@saurabh-laptop:/opt$ wget http://rubyforge.org/frs/download.php/69546/passenger-2.2.11.tar.gz</pre>
</li>
<li>Unzip the downloaded archive like this:
<pre>saurabh@saurabh-laptop:~$ tar xvzf passenger-2.2.11.tar.gz</pre>
</li>
<li>Change the directory to <em>bin</em> inside the extracted Passenger folder and run the binary to install the Apache2 module, as follows:
<pre>saurabh@saurabh-laptop:~/opt/passenger-2.2.11/bin$ ./passenger-install-apache2-module</pre>
</li>
</ol>
<p>The third way to install Passenger is by using the native Deb package. (The steps for this are the same as those shown in Figures 1-3.) This approach is specific to Debian and Debian-based distributions like <a href="http://wiki.brightbox.co.uk/docs:brightboxaptrepository" target="newFrame">Brightbox Ubuntu</a>, a UK-based hosting repository that provides a package tested on Ubuntu 8.04.</p>
<p>First, open your favorite editor (nano in my case), so you can add the <em>ppa</em> line to the sources file.</p>
<pre>saurabh@saurabh-laptop:~$ nano /etc/apt/sources.list</pre>
<p>Next, add the <em>ppa</em> line at the end of the file and add the signature like this:</p>
<pre>deb http://apt.brightbox.net hardy main

sudo sh -c 'wget -q -O - http://apt.brightbox.net/release.asc | apt-key add -'

saurabh@saurabh-laptop:~$sudo apt-get update

saurabh@saurabh-laptop:~$sudo apt-get install libapache2-mod-passenger</pre>
<p>When these steps are complete, you are ready to serve your applications via Apache2 mod_rails and you can proceed to configuring your Apache server and deploying your app to it.</p>
<h3>Apache Configuration</h3>
<p>Move the Rails application to the <em>/var/www</em> folder on your server and start editing the Apache configuration file to add a virtual host. Point the document root to the <em>public</em> folder of the application, as follows:</p>
<pre>saurabh@saurabh-laptop:~$ nano /etc/apache2/sites-enabled/000-default 

&lt;VirtualHost *:80&gt;
        ServerAdmin webmaster@localhost 

        ServerName www.mywebsite.com
        DocumentRoot /var/www/mywebsite/public
        &lt;Directory /var/www/mywebsite/public&gt;
                Options Indexes FollowSymLinks -MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        &lt;/Directory&gt; 

        ErrorLog /var/log/apache2/error.log 

        LogLevel warn 

        CustomLog /var/log/apache2/access.log combined 

&lt;/VirtualHost&gt;</pre>
<p>Next, simply start your Apache server like this:</p>
<pre>saurabh@saurabh-laptop:~$ /etc/init.d/apache start</pre>
<p>Now, navigate to your domain in the browser and you will see your application running in the browser.</p>
<h3>Deploying Multiple Rails Applications in Passenger</h3>
<p>You can deploy multiple Rails applications in two ways, depending on the type of URI you want to deploy to. The first one is deploying to a sub URL, which looks something like this: <em>www.mywebsite.com/suburl</em>. The second one is deploying to a subdomain, which looks like this:<em>www.subapplication.mywebsite.com</em>.</p>
<p>Let&#8217;s take the first way, serving your application at <em>www.mywebsite.com/suburl</em>. Suppose your apps reside in <em>/var/www/mywebsite/</em> and your document root is set to <em>/mywebsites/</em>. First, create a symbolic link from the <em>Public</em> folder of the app to the directory created inside the document root of the <em>mywebsites</em>folder as shown below:</p>
<pre>ln -s /var/www/mywebsite/suburl/public /var/www/mywebsite/suburl</pre>
<p>You have already seen how to create a virtual host for your Rails app. This is how it looks in this case:</p>
<pre>&lt;VirtualHost *:80&gt;
        ServerAdmin webmaster@localhost 

        ServerName www.mywebsite.com
        DocumentRoot /var/www/ mywebsite
        &lt;Directory /var/www/mywebsite&gt;
                Options Indexes FollowSymLinks -MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        &lt;/Directory&gt; 

        ErrorLog /var/log/apache2/error.log 

        LogLevel warn 

        CustomLog /var/log/apache2/access.log combined 

&lt;/VirtualHost&gt;</pre>
<p>Before proceeding further, verify two things:</p>
<ol>
<li>Apache has the appropriate permissions for every application directory.</li>
<li>Multiviews is disabled for this folder.</li>
</ol>
<p>When you are sure of these requirements, add a <em>RailsBaseURI</em> directive to the virtual host configuration as follows. You can define as many<em>RailsBaseURI</em>s as you want.</p>
<pre>&lt;VirtualHost *:80&gt;
        ServerName www.mywebsite.com
        DocumentRoot /var/www/ mywebsite
        &lt;Directory /var/www/mywebsite&gt;
                Options Indexes FollowSymLinks -MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        &lt;/Directory&gt; 

    RailsBaseURI /suburl
    &lt;Directory /var/www/mywebsite/suburl&gt;
        Options -MultiViews
    &lt;/Directory&gt;                        

        ErrorLog /var/log/apache2/error.log 

        LogLevel warn 

        CustomLog /var/log/apache2/access.log combined 

&lt;/VirtualHost&gt;</pre>
<p>When you edited and saved your virtual host configuration, restart the Apache server with the following command:</p>
<pre>/etc/init.d/apache2 restart</pre>
<h3>Conclusion</h3>
<p>Phusion Passenger is the most popular way to deploy Rails applications to Apache HTTP Server, because it offers multiple Apache scaling techniques. But its biggest advantage is that PHP apps can run in the same server. So, if a person wants to run his or her WordPress blog in the Rails application, Apache makes that possible also.</p>
<h3>About the Author</h3>
<p><em><strong>Saurabh Bhatia</strong> has been working with Rails since early 2006 and has a startup company, <a href="http://safewlabs.com/" target="newFrame">Safew Labs</a>, that offers Rails consulting. He likes to write clean code, read and write.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=84</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reserved Words You Can’t Use</title>
		<link>http://www.alanmaciel.net/?p=72&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=reserved-words-you-can%25e2%2580%2599t-use</link>
		<comments>http://www.alanmaciel.net/?p=72#comments</comments>
		<pubDate>Mon, 01 Aug 2011 08:56:13 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[howtos]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=72</guid>
		<description><![CDATA[ADDITIONAL_LOAD_PATHS ARGF ARGV ActionController ActionView ActiveRecord ArgumentError Array BasicSocket Benchmark Bignum Binding CGI CGIMethods CROSS_COMPILING Class ClassInheritableAttributes Comparable ConditionVariable Config Configuration Continuation DRb DRbIdConv DRbObject DRbUndumped Data Date DateTime Delegater Delegator Digest Dir ENV EOFError ERB Enumerable Errno Exception FALSE FalseClass Fcntl File FileList FileTask FileTest FileUtils Fixnum Float FloatDomainError GC Gem GetoptLong Hash IO [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">
<ul>
<li><span style="line-height: normal;">ADDITIONAL_LOAD_PATHS</span></li>
<li><span style="line-height: normal;">ARGF</span></li>
<li><span style="line-height: normal;">ARGV</span></li>
<li><span style="line-height: normal;">ActionController</span></li>
<li><span style="line-height: normal;">ActionView</span></li>
<li><span style="line-height: normal;">ActiveRecord</span></li>
<li><span style="line-height: normal;">ArgumentError</span></li>
<li><span style="line-height: normal;">Array</span></li>
<li><span style="line-height: normal;">BasicSocket</span></li>
<li><span style="line-height: normal;">Benchmark</span></li>
<li><span style="line-height: normal;">Bignum</span></li>
<li><span style="line-height: normal;">Binding</span></li>
<li><span style="line-height: normal;">CGI</span></li>
<li><span style="line-height: normal;">CGIMethods</span></li>
<li><span style="line-height: normal;">CROSS_COMPILING</span></li>
<li><span style="line-height: normal;">Class</span></li>
<li><span style="line-height: normal;">ClassInheritableAttributes</span></li>
<li><span style="line-height: normal;">Comparable</span></li>
<li><span style="line-height: normal;">ConditionVariable</span></li>
<li><span style="line-height: normal;">Config</span></li>
<li><span style="line-height: normal;">Configuration</span></li>
<li><span style="line-height: normal;">Continuation</span></li>
<li><span style="line-height: normal;">DRb</span></li>
<li><span style="line-height: normal;">DRbIdConv</span></li>
<li><span style="line-height: normal;">DRbObject</span></li>
<li><span style="line-height: normal;">DRbUndumped</span></li>
<li><span style="line-height: normal;">Data</span></li>
<li><span style="line-height: normal;">Date</span></li>
<li><span style="line-height: normal;">DateTime</span></li>
<li><span style="line-height: normal;">Delegater</span></li>
<li><span style="line-height: normal;">Delegator</span></li>
<li><span style="line-height: normal;">Digest</span></li>
<li><span style="line-height: normal;">Dir</span></li>
<li><span style="line-height: normal;">ENV</span></li>
<li><span style="line-height: normal;">EOFError</span></li>
<li><span style="line-height: normal;">ERB</span></li>
<li><span style="line-height: normal;">Enumerable</span></li>
<li><span style="line-height: normal;">Errno</span></li>
<li><span style="line-height: normal;">Exception</span></li>
<li><span style="line-height: normal;">FALSE</span></li>
<li><span style="line-height: normal;">FalseClass</span></li>
<li><span style="line-height: normal;">Fcntl</span></li>
<li><span style="line-height: normal;">File</span></li>
<li><span style="line-height: normal;">FileList</span></li>
<li><span style="line-height: normal;">FileTask</span></li>
<li><span style="line-height: normal;">FileTest</span></li>
<li><span style="line-height: normal;">FileUtils</span></li>
<li><span style="line-height: normal;">Fixnum</span></li>
<li><span style="line-height: normal;">Float</span></li>
<li><span style="line-height: normal;">FloatDomainError</span></li>
<li><span style="line-height: normal;">GC</span></li>
<li><span style="line-height: normal;">Gem</span></li>
<li><span style="line-height: normal;">GetoptLong</span></li>
<li><span style="line-height: normal;">Hash</span></li>
<li><span style="line-height: normal;">IO</span></li>
<li><span style="line-height: normal;">IOError</span></li>
<li><span style="line-height: normal;">IPSocket</span></li>
<li><span style="line-height: normal;">IPsocket</span></li>
<li><span style="line-height: normal;">IndexError</span></li>
<li><span style="line-height: normal;">Inflector</span></li>
<li><span style="line-height: normal;">Integer</span></li>
<li><span style="line-height: normal;">Interrupt</span></li>
<li><span style="line-height: normal;">Kernel</span></li>
<li><span style="line-height: normal;">LN_SUPPORTED</span></li>
<li><span style="line-height: normal;">LoadError</span></li>
<li><span style="line-height: normal;">LocalJumpError</span></li>
<li><span style="line-height: normal;">Logger</span></li>
<li><span style="line-height: normal;">Marshal</span></li>
<li><span style="line-height: normal;">MatchData</span></li>
<li><span style="line-height: normal;">MatchingData</span></li>
<li><span style="line-height: normal;">Math</span></li>
<li><span style="line-height: normal;">Method</span></li>
<li><span style="line-height: normal;">Module</span></li>
<li><span style="line-height: normal;">Mutex</span></li>
<li><span style="line-height: normal;">Mysql</span></li>
<li><span style="line-height: normal;">MysqlError</span></li>
<li><span style="line-height: normal;">MysqlField</span></li>
<li><span style="line-height: normal;">MysqlRes</span></li>
<li><span style="line-height: normal;">NIL</span></li>
<li><span style="line-height: normal;">NameError</span></li>
<li><span style="line-height: normal;">NilClass</span></li>
<li><span style="line-height: normal;">NoMemoryError</span></li>
<li><span style="line-height: normal;">NoMethodError</span></li>
<li><span style="line-height: normal;">NoWrite</span></li>
<li><span style="line-height: normal;">NotImplementedError</span></li>
<li><span style="line-height: normal;">Numeric</span></li>
<li><span style="line-height: normal;">OPT_TABLE</span></li>
<li><span style="line-height: normal;">Object</span></li>
<li><span style="line-height: normal;">ObjectSpace</span></li>
<li><span style="line-height: normal;">Observable</span></li>
<li><span style="line-height: normal;">PGError</span></li>
<li><span style="line-height: normal;">PGconn</span></li>
<li><span style="line-height: normal;">PGlarge</span></li>
<li><span style="line-height: normal;">PGresult</span></li>
<li><span style="line-height: normal;">PLATFORM</span></li>
<li><span style="line-height: normal;">PStore</span></li>
<li><span style="line-height: normal;">ParseDate</span></li>
<li><span style="line-height: normal;">Precision</span></li>
<li><span style="line-height: normal;">Proc</span></li>
<li><span style="line-height: normal;">Process</span></li>
<li><span style="line-height: normal;">Queue</span></li>
<li><span style="line-height: normal;">RAKEVERSION</span></li>
<li><span style="line-height: normal;">RELEASE_DATE</span></li>
<li><span style="line-height: normal;">RUBY</span></li>
<li><span style="line-height: normal;">RUBY_PLATFORM</span></li>
<li><span style="line-height: normal;">RUBY_RELEASE_DATE</span></li>
<li><span style="line-height: normal;">RUBY_VERSION</span></li>
<li><span style="line-height: normal;">Rake</span></li>
<li><span style="line-height: normal;">RakeApp</span></li>
<li><span style="line-height: normal;">RakeFileUtils</span></li>
<li><span style="line-height: normal;">Range</span></li>
<li><span style="line-height: normal;">RangeError</span></li>
<li><span style="line-height: normal;">Rational</span></li>
<li><span style="line-height: normal;">Regexp</span></li>
<li><span style="line-height: normal;">RegexpError</span></li>
<li><span style="line-height: normal;">Request</span></li>
<li><span style="line-height: normal;">Responder</span></li>
<li><span style="line-height: normal;">RuntimeError</span></li>
<li><span style="line-height: normal;">STDERR</span></li>
<li><span style="line-height: normal;">STDIN</span></li>
<li><span style="line-height: normal;">STDOUT</span></li>
<li><span style="line-height: normal;">ScanError</span></li>
<li><span style="line-height: normal;">ScriptError</span></li>
<li><span style="line-height: normal;">SecurityError</span></li>
<li><span style="line-height: normal;">Signal</span></li>
<li><span style="line-height: normal;">SignalException</span></li>
<li><span style="line-height: normal;">SimpleDelegater</span></li>
<li><span style="line-height: normal;">SimpleDelegator</span></li>
<li><span style="line-height: normal;">Singleton</span></li>
<li><span style="line-height: normal;">SizedQueue</span></li>
<li><span style="line-height: normal;">Socket</span></li>
<li><span style="line-height: normal;">SocketError</span></li>
<li><span style="line-height: normal;">StandardError</span></li>
<li><span style="line-height: normal;">String</span></li>
<li><span style="line-height: normal;">StringScanner</span></li>
<li><span style="line-height: normal;">Struct</span></li>
<li><span style="line-height: normal;">Symbol</span></li>
<li><span style="line-height: normal;">SyntaxError</span></li>
<li><span style="line-height: normal;">SystemCallError</span></li>
<li><span style="line-height: normal;">SystemExit</span></li>
<li><span style="line-height: normal;">SystemStackError</span></li>
<li><span style="line-height: normal;">TCPServer</span></li>
<li><span style="line-height: normal;">TCPSocket</span></li>
<li><span style="line-height: normal;">TCPserver</span></li>
<li><span style="line-height: normal;">TCPsocket</span></li>
<li><span style="line-height: normal;">TOPLEVEL_BINDING</span></li>
<li><span style="line-height: normal;">TRUE</span></li>
<li><span style="line-height: normal;">Task</span></li>
<li><span style="line-height: normal;">Text</span></li>
<li><span style="line-height: normal;">Thread</span></li>
<li><span style="line-height: normal;">ThreadError</span></li>
<li><span style="line-height: normal;">ThreadGroup</span></li>
<li><span style="line-height: normal;">Time</span></li>
<li><span style="line-height: normal;">Transaction</span></li>
<li><span style="line-height: normal;">TrueClass</span></li>
<li><span style="line-height: normal;">TypeError</span></li>
<li><span style="line-height: normal;">UDPSocket</span></li>
<li><span style="line-height: normal;">UDPsocket</span></li>
<li><span style="line-height: normal;">UNIXServer</span></li>
<li><span style="line-height: normal;">UNIXSocket</span></li>
<li><span style="line-height: normal;">UNIXserver</span></li>
<li><span style="line-height: normal;">UNIXsocket</span></li>
<li><span style="line-height: normal;">UnboundMethod</span></li>
<li><span style="line-height: normal;">Url</span></li>
<li><span style="line-height: normal;">VERSION</span></li>
<li><span style="line-height: normal;">Verbose</span></li>
<li><span style="line-height: normal;">YAML</span></li>
<li><span style="line-height: normal;">ZeroDivisionError</span></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=72</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OPCIONES DE INICIO DE APP</title>
		<link>http://www.alanmaciel.net/?p=70&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=opciones-de-inicio-de-app</link>
		<comments>http://www.alanmaciel.net/?p=70#comments</comments>
		<pubDate>Sat, 30 Jul 2011 08:55:12 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[howtos]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=70</guid>
		<description><![CDATA[Opcion 1 &#8212;&#8212;&#8212;&#8212; Todo desde abajo en Rails Opcion 2 &#8212;&#8212;&#8212;&#8212; Utilizar Base app y saas Opcion 3 &#8212;&#8212;&#8212;&#8212; utilizar goldberg u otro tipo de startkit]]></description>
			<content:encoded><![CDATA[<p>Opcion 1</p>
<p>&#8212;&#8212;&#8212;&#8212;</p>
<p>Todo desde abajo en Rails</p>
<p>Opcion 2</p>
<p>&#8212;&#8212;&#8212;&#8212;</p>
<p>Utilizar Base app y</p>
<p>saas</p>
<p>Opcion 3</p>
<p>&#8212;&#8212;&#8212;&#8212;</p>
<p>utilizar goldberg u otro</p>
<p>tipo de startkit</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=70</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing kete-tiny_mce</title>
		<link>http://www.alanmaciel.net/?p=68&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=installing-kete-tiny_mce</link>
		<comments>http://www.alanmaciel.net/?p=68#comments</comments>
		<pubDate>Fri, 29 Jul 2011 08:54:15 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=68</guid>
		<description><![CDATA[Informacion original en http://github.com/kete/tiny_mce Instalar el gem: sudo gem install kete-tiny_mce Add this to config/environment.rb of your Rails application: config.gem ‘kete-tiny_mce’, :lib =&#62; ‘tiny_mce’, :source =&#62; ‘gems.github.com‘ Se agrega al controller: uses_tiny_mce ptions =&#62; { :theme =&#62; &#8216;advanced&#8217;, :theme_advanced_resizing =&#62; true, :theme_advanced_resize_horizontal =&#62; true, :plugins =&#62; %w{safari spellchecker pagebreak style layer table save advhr advimage [...]]]></description>
			<content:encoded><![CDATA[<p>Informacion original en <a href="http://github.com/kete/tiny_mce">http://github.com/kete/tiny_mce</a></p>
<p>Instalar el gem:</p>
<p>sudo gem install kete-tiny_mce</p>
<p>Add this to config/environment.rb of your Rails application:</p>
<p>config.gem ‘kete-tiny_mce’, :lib =&gt; ‘tiny_mce’, :source =&gt; ‘gems.github.com‘</p>
<p>Se agrega al controller:</p>
<p>uses_tiny_mce <img src='http://www.alanmaciel.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ptions =&gt; {</p>
<p>:theme =&gt; &#8216;advanced&#8217;,</p>
<p>:theme_advanced_resizing =&gt; true,</p>
<p>:theme_advanced_resize_horizontal =&gt; true,</p>
<p>:plugins =&gt; %w{safari spellchecker pagebreak style layer table save advhr advimage advlink emotions iespell inlinepopups insertdatetime preview media searchreplace print contextmenu paste directionality fullscreen noneditable visualchars nonbreaking xhtmlxtras template imagemanager filemanager },</p>
<p>:theme_advanced_buttons1 =&gt; %w{save newdocument | bold italic underline strikethrough | justifyleft justifycenter justifyright justifyfull | styleselect formatselect fontselect fontsizeselect},</p>
<p>:theme_advanced_buttons2 =&gt; %w{cut copy paste pastetext pasteword | search replace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image cleanup help code | insertdate inserttime preview | forecolor backcolor},</p>
<p>:theme_advanced_buttons3 =&gt; %w{tablecontrols | hr removeformat visualaid | sub sup | charmap emotions iespell media advhr | print | ltr rtl | fullscreen},</p>
<p>:theme_advanced_buttons4 =&gt; %w{insertlayer moveforward movebackward absolute | styleprops spellchecker | cite abbr acronym del ins attribs | visualchars nonbreaking template blockquote pagebreak | insertfile insertimage},</p>
<p>:theme_advanced_toolbar_location =&gt; &#8216;top&#8217;,</p>
<p>:theme_advanced_toolbar_align =&gt; &#8216;left&#8217;,</p>
<p>:theme_advanced_statusbar_location =&gt; &#8216;bottom&#8217;,</p>
<p>:theme_advanced_resizing =&gt; true</p>
<p>},</p>
<p> <img src='http://www.alanmaciel.net/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly =&gt; [:new, :create, :edit, :update]</p>
<p>Y a la form en el view se agrega:</p>
<p>:class =&gt; &#8220;mceEditor&#8221;</p>
<p>Y por ultimo se agrega al &lt;head&gt; del application view:</p>
<p>&lt;%= include_tiny_mce_if_needed %&gt;</p>
<p>Documentacion de opciones en:</p>
<p>http://tinymce.moxiecode.com/examples/example_01.php</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=68</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec cheatsheet</title>
		<link>http://www.alanmaciel.net/?p=66&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rspec-cheatsheet</link>
		<comments>http://www.alanmaciel.net/?p=66#comments</comments>
		<pubDate>Thu, 28 Jul 2011 08:53:07 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[howtos]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=66</guid>
		<description><![CDATA[INSTALL ======= INSTALL rspec ============= $ sudo gem install rspec OR $ ./script/plugin install git://github.com/dchelimsky/rspec.git INSTALL rspec_on_rails plugin ============================= $ ./script/plugin install git://github.com/dchelimsky/rspec-rails.git BOOTSTRAP THE APP ================= $ ./script/generate rspec create spec create spec/spec_helper.rb create spec/spec.opts create previous_failures.txt create script/spec_server create script/spec HOW TO USE ========== COMMAND LINE ============= spec &#8211;color &#8211;format specdoc user.rspec RAILS [...]]]></description>
			<content:encoded><![CDATA[<div><span style="line-height: 18px;"><span style="line-height: normal;">INSTALL =======</p>
<p>INSTALL rspec</p>
<p>============= $ sudo gem install rspec</p>
<p>OR $ ./script/plugin install git://github.com/dchelimsky/rspec.git</p>
<p>INSTALL rspec_on_rails plugin</p>
<p>============================= $ ./script/plugin install git://github.com/dchelimsky/rspec-rails.git</p>
<p>BOOTSTRAP THE APP ================= $ ./script/generate rspec</p>
<p>create spec create spec/spec_helper.rb create spec/spec.opts create previous_failures.txt create script/spec_server create script/spec</p>
<p>HOW TO USE ==========</p>
<p>COMMAND LINE</p>
<p>============= spec &#8211;color &#8211;format specdoc user.rspec</p>
<p>RAILS</p>
<p>============= ./script/generate rspec_model User rake doc:plugins # generates local docs for your app&#8217;s plugins rake -T spec # lists all rspec rake tasks rake spec # run all specs rake spec SPEC=spec/models/mymodel_spec.rb SPEC_OPTS=&#8221;-e \&#8221;should do something\&#8221;" #run a single spec</p>
<p>module UserSpecHelper def valid_user_attributes</p>
<p>{ :email =&gt; &#8220;joe@bloggs.com&#8221;, :username =&gt; &#8220;joebloggs&#8221;, :password =&gt; &#8220;abcdefg&#8221;}</p>
<p>end end</p>
<p>describe &#8220;A User (in general)&#8221; do include UserSpecHelper</p>
<p><strong>$ cheat rspec</strong></p>
<p>before(:each) do @user = User.new</p>
<p>end</p>
<p>it &#8220;should be invalid without a username&#8221; do pending &#8220;some other thing we depend on&#8221; @user.attributes = valid_user_attributes.except(:username) @user.should_not be_valid @user.should have(1).error_on(:username) @user.errors.on(:username).should == &#8220;is required&#8221; @user.username = &#8220;someusername&#8221; @user.should be_valid</p>
<p>end end</p>
<p>SHOULDA COULDA WOULDA ===================== target.should satisfy {|arg| &#8230;} target.should_not satisfy {|arg| &#8230;}</p>
<p>target.should equal &lt;value&gt; target.should not_equal &lt;value&gt;</p>
<p>target.should be_close &lt;value&gt;, &lt;tolerance&gt; target.should_not be_close &lt;value&gt;, &lt;tolerance&gt;</p>
<p>target.should be &lt;value&gt; target.should_not be &lt;value&gt;</p>
<p>target.should predicate [optional args] target.should be_predicate [optional args] target.should_not predicate [optional args] target.should_not be_predicate [optional args]</p>
<p>target.should be &lt; 6 target.should == 5 target.should_not == &#8216;Samantha&#8217;</p>
<p>target.should match &lt;regex&gt; target.should_not match &lt;regex&gt;</p>
<p>target.should be_an_instance_of &lt;class&gt; target.should_not be_an_instance_of &lt;class&gt;</p>
<p>target.should be_a_kind_of &lt;class&gt; target.should_not be_a_kind_of &lt;class&gt;</p>
<p>target.should respond_to &lt;symbol&gt; target.should_not respond_to &lt;symbol&gt;</p>
<p>*OLD:* proc.should raise &lt;exception&gt; proc.should_not raise &lt;exception&gt; proc.should_raise &lt;exception&gt; # not available anymore *NEW:* lambda lambda lambda lambda</p>
<p>{a_call}.should raise_error {a_call}.should raise_error(&lt;exception&gt; [, message]) {a_call}.should_not raise_error {a_call}.should_not raise_error(&lt;exception&gt; [, message])</p>
<p>proc.should throw &lt;symbol&gt;</p>
<p>proc.should_not throw &lt;symbol&gt;</p>
<p>target.should include &lt;object&gt; target.should_not include &lt;object&gt;</p>
<p>target.should have(&lt;number&gt;).things target.should have_at_least(&lt;number&gt;).things target.should have_at_most(&lt;number&gt;).things</p>
<p>target.should have(&lt;number&gt;).errors_on(:field)</p>
<p>proc { thing.approve! }.should change(thing, :status). from(Status::AWAITING_APPROVAL). to(Status::APPROVED)</p>
<p>proc { thing.destroy }.should change(Thing, :count).by(-1)</p>
<p>Mocks and Stubs ===============</p>
<p>user_mock = mock &#8220;User&#8221; user_mock.should_receive(:authenticate).with(&#8220;password&#8221;).and_return(true) user_mock.should_receive(:coffee).exactly(3).times.and_return(:americano) user_mock.should_receive(:coffee).exactly(5).times.and_raise(NotEnoughCoffeeExcep ion)</p>
<p>people_stub = mock &#8220;people&#8221; people_stub.stub!(:each).and_yield(mock_user) people_stub.stub!(:bad_method).and_raise(RuntimeError)</p>
<p>user_stub = mock_model(&#8220;User&#8221;, :id =&gt; 23, :username =&gt; &#8220;pat&#8221;, :email =&gt; &#8220;pat@example.com&#8221;)</p>
<p>Examples (in the real world) ============================ http://madhatted.com/2008/7/10/rspec-real-world-testing</p>
<p></span></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=66</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery in Rails</title>
		<link>http://www.alanmaciel.net/?p=64&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-in-rails</link>
		<comments>http://www.alanmaciel.net/?p=64#comments</comments>
		<pubDate>Wed, 27 Jul 2011 08:50:34 +0000</pubDate>
		<dc:creator>Alan M.</dc:creator>
				<category><![CDATA[howtos]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.alanmaciel.net/?p=64</guid>
		<description><![CDATA[extracted from Ryan Bates railscast 136: jQuery We know how to update multiple elements on a page in the response from an AJAX request. We used the Prototype libraries and form_remote_for to submit a form asynchronously and RJS to generate the JavaScript that would update the elements on the page in the response. In this [...]]]></description>
			<content:encoded><![CDATA[<p><strong>extracted from Ryan Bates railscast 136: jQuery</strong></p>
<p>We know how to update multiple elements on a page in the response from an AJAX request. We used the Prototype libraries and form_remote_for to submit a form asynchronously and RJS to generate the JavaScript that would update the elements on the page in the response. In this episode we’re going to use jQuery, rather than Prototype and RJS, to do the same thing.</p>
<p>As we’re using jQuery we won’t be able to use RJS or any of the helper methods such as form_remote_for that Rails provides. If we still wanted to be able to use RJS there is a plugin called jRails that will rewrite those methods to work with jQuery, but we’re going to use jQuery on its own as it provides a way of writing unobtrusive JavaScript to enhance our Rails application.</p>
<p>We’ll be working with the same application we used before. The page below shows a product and allows customers to add reviews for it. When a new review is added it appears in the reviews list, the text showing the number of reviews is updated, the form is reset and a flash message is shown thanking the user for adding their review.</p>
<p>The application currently posts back and reloads the page when a product is added. We’re going to write some jQuery code to make the form send its data back via an AJAX request and then update the page without it having to be reloaded.</p>
<p><strong>Adding jQuery To Our Application</strong></p>
<p>The first thing we’ll need to do is add the jQuery library to our application. It can be downloaded from the jQuery website and once downloaded it belongs in the public/javascripts directory. Next, we’ll need to reference it from our application’s layout page by putting the following line into the &lt;head&gt; section.</p>
<p>1. &lt;%= javascript_include_tag ['jquery-1.3.2', 'application'] %&gt;</p>
<p>Each release of jQuery is available in two versions; one for development and a minified version for production. It’s best to use the development version when you’re developing your site as it makes debugging your jQuery code easier. As well as the jQuery file we’ll also need to reference the application.js file as it’s here that we’ll be putting our jQuery code. Note that the jQuery file is added first so that it’s loaded before the application’s JavaScript file.</p>
<p><strong>Adding Unobtrusive JavaScript</strong></p>
<p>To add JavaScript unobtrusively we don’t want to modify the code in our view files at all. Instead we’ll be using jQuery to modify the behaviour of elements on the page dynamically. We’ll start off by writing a function that will run when the form is submitted.</p>
<p>Our form has an id of new_review. The code below will cause it to be submitted via AJAX.</p>
<p>1. 2. 3. 4. 5. 6.</p>
<p>$(document).ready(function (){ $(&#8216;#new_review&#8217;).submit(function (){</p>
<p>$.post($(this).attr(&#8216;action&#8217;), $(this).serialize(), null, &#8220;script&#8221;);</p>
<p>return false; });</p>
<p>});</p>
<p>The first line in the above code creates a function that will be run when the document’s object model is loaded. The second line finds our form by its id and creates a function that will run when the form is submitted. The third line creates the AJAX request that will be POSTed to the server. The $.post function takes four arguments. The first is the URL that will be posted to, for which we supply the value of the form’s action attribute. The second argument is the data that should be posted. For this we use jQuery’s serialize method which will handily serialize the form’s elements as a series of key / value pairs for sending to the server. The next argument is a callback function that will be executed when the AJAX request completes, but we won’t be using that so we’ve supplied null. The reason we don’t have a callback function is that we can tell the function that we’re returning JavaScript that should be run by the browser and we do this by supplying “script” as the fourth argument. For more details about $.post see the jQuery documentation. Finally we return false so that the default submit action doesn’t fire.</p>
<p><strong>Updating The Controller</strong></p>
<p>Now that we have our form submitting via AJAX we’ll have to modify our reviews controller so that it can deal with both HTML and JavaScript requests. Currently it saves the new review then redirects to the product’s page. A redirect makes no sense in the context of a JavaScript request so the page will need to respond differently for these. We’ll use respond_to to set up two different blocks.</p>
<p>1. 2. 3. 4. 5. 6. 7. 8.</p>
<p>def create <strong>@review </strong>= Review.create!(params[:review]) flash[:notice] = &#8220;Thanks for your review!&#8221; respond_to do |format|</p>
<p>format.html { redirect_to <strong>@review</strong>.product }</p>
<p>format.js end</p>
<p>end</p>
<p>The js block is empty as all it needs to do is return the JavaScript we create. This will live in a file called create.js.erb in the /app/views/reviews directory. Without jRails we can’t use RJS with jQuery, so we’re using a js.erb file instead. To get going we’ll add a simple alert to create.js.erb to test that our code works.</p>
<p>1. alert(&#8216;Hello from AJAX&#8217;);</p>
<p>Before we test it, there’s one more thing we need to do. As it stands the code won’t work, and the reason for that is that Rails doesn’t know what format the request that jQuery sends is in, so defaults to HTML. We’ll need to tell Rails that we’re sending a JavaScript request.</p>
<p>There are two ways to do this. We could add a .js extension to the URL the AJAX request makes, or we could use jQuery’s ajaxSetup method to set the request header so that it only accepts JavaScript. This second method has the advantage that it only needs to be done once and it will work for every AJAX request in our code. We’ll do that by adding the line below to the top of application.js.</p>
<p>1. jQuery.ajaxSetup({ 2.	&#8216;beforeSend&#8217;: function (xhr) {xhr.setRequestHeader(&#8220;Accept&#8221;, &#8220;text/javascript&#8221;)} 3. });</p>
<p>Adding the header will tell Rails to call the js block and return the contents of the js.erb file. We can now refresh the page and try adding a review.</p>
<p>The response from create.js.erb in the browser.</p>
<p><strong>Updating The Page</strong></p>
<p>The alert shows, so we know that our create.js.erb file is being returned and executed by the browser. We can now replace the alert with the jQuery code that will update the page after a new review has been added. There are four things we want to do.</p>
<p>First we’ll add the flash message to the page that thanks the user for adding their review. We’ll do this by adding a div before the form.</p>
<p>1. $(&#8216;#new_review&#8217;).before(&#8216;&lt;div id=&#8221;flash_notice&#8221;&gt;&lt;%= escape_javascript(flash.delete(:notice)) %&gt;&lt;/div&gt;&#8217;);</p>
<p>To add dynamic content we just use erb tags embedded in the JavaScript. We use escape_javascript to make anything output from erb JavaScript safe. Note that we’re calling flash.delete to clear the flash message immediately so that it is not redisplayed in the next request.</p>
<p>The element that holds the reviews count will also need to be updated. It has an id of reviews_count and jQuery’s html method can be used to update its contents.</p>
<p>1. $(&#8216;#reviews_count&#8217;).html(&#8216;&lt;%= pluralize(@review.product.reviews.count, &#8220;Review&#8221;) %&gt;&#8217;);</p>
<p>Next we’ll add the new review to the list. The reviews are displayed in an ordered list with an id of reviews. Each review is rendered as a list item from a partial. To add our new review we can render the partial for our new review and append it to the list.</p>
<p>1. $(&#8216;#reviews&#8217;).append(&#8220;&lt;%= escape_javascript(render(:partial =&gt; @review)) %&gt;&#8221;); And finally, we’ll reset the form.</p>
<p>1. $(&#8216;#new_review&#8217;)[0].reset(); The jQuery function, $, returns a jQuery object. To get at the actual DOM element it represents we get the first element</p>
<p>from the array. We then call reset() on it to clear the form.</p>
<p><strong>Extending jQuery</strong></p>
<p>To finish this episode we’ll show you how easy it is to add your own functions to jQuery. We currently have some jQuery code that runs when the form is submitted.</p>
<p>1. $(&#8216;#new_review&#8217;).submit(function (){ 2.	$.post($(this).attr(&#8216;action&#8217;), $(this).serialize(), null, &#8220;script&#8221;); 3.	return false; 4. });</p>
<p>If we wanted to do this across several forms on our site we can extract that code out into a new jQuery function so that we could call</p>
<p>1. $(&#8216;#new_review&#8217;).submitWithAjax(); instead. jQuery is easy to extend with custom functions. We can create our new function by writing</p>
<p>1. 2. 3. 4. 5. 6.</p>
<p>jQuery.fn.submitWithAjax = function () { this.submit(function () {</p>
<p>$.post($(this).attr(&#8216;action&#8217;), $(this).serialize(), null, &#8220;script&#8221;);</p>
<p>return false; });</p>
<p>}; That’s all we have to do. Now we can submit any form asynchronously by calling submitWithAjax on it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alanmaciel.net/?feed=rss2&#038;p=64</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
