<?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>John Yerhot - Weblog &#187; Ruby On Rails</title>
	<atom:link href="http://www.johnyerhot.com/tag/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johnyerhot.com</link>
	<description>im in ur computrz makin castz</description>
	<lastBuildDate>Tue, 29 Jun 2010 04:32:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>rDigg &#8211; Ruby on Rails Digg API plugin</title>
		<link>http://www.johnyerhot.com/2008/08/14/rdigg-ruby-on-rails-digg-api-plugin/</link>
		<comments>http://www.johnyerhot.com/2008/08/14/rdigg-ruby-on-rails-digg-api-plugin/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 20:09:01 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[digg.com]]></category>
		<category><![CDATA[rDigg]]></category>

		<guid isPermaLink="false">http://www.johnyerhot.com/?p=85</guid>
		<description><![CDATA[I&#8217;ve sort of finished up rDigg today.  It&#8217;s to the point I&#8217;m comfortable letting other people start to play with it anyways.
As you&#8217;d expect, rDigg is a Digg API wrapper in the form of a Ruby on Rails plugin.   It still needs some work, but works pretty well.
For example:
#create new Rdigg object
digg [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve sort of finished up rDigg today.  It&#8217;s to the point I&#8217;m comfortable letting other people start to play with it anyways.</p>
<p>As you&#8217;d expect, rDigg is a <a href="http://digg.com">Digg</a> API wrapper in the form of a Ruby on Rails plugin.   It still needs some work, but works pretty well.</p>
<p>For example:</p>
<pre>#create new Rdigg object
digg = Rdigg.new

# find the 3 newest submissions from Kevin Rose
stories = digg.user.find_submissions("kevinrose", :count =&gt; 3)

# stories is now an array with a hash for each story
stories.first[:story] #=&gt; the story's text
stories.first[:href] #=&gt; the story's url
stories.first[:diggs] #=&gt; number of diggs the story has</pre>
<p>Grab it  at: <a href="http://github.com/johnyerhot/rdigg/tree/master">http://github.com/johnyerhot/rdigg/tree/master</a>.  <del datetime="2008-08-15T01:20:18+00:00">I&#8217;ll have the Rdoc up at rdigg.yerhot.org later tonight</del> You can peruse the documentation at <a href="http://rdigg.yerhot.org">rdigg.yerhot.org</a>. I highly recommend you check out all methods that are available to you.</p>
<p>If you want to really dig in (sorry couldn&#8217;t resist) I&#8217;d go over the <a href="http://apidoc.digg.com/">Digg API wiki</a> to see what arguments you can pass.</p>
<p>I hope you enjoy the plugin!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnyerhot.com/2008/08/14/rdigg-ruby-on-rails-digg-api-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rentalrundown.com and Seattle trip</title>
		<link>http://www.johnyerhot.com/2008/06/09/rentalrundowncom-and-seattle-trip/</link>
		<comments>http://www.johnyerhot.com/2008/06/09/rentalrundowncom-and-seattle-trip/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 03:25:58 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Seattle]]></category>
		<category><![CDATA[Vacations]]></category>
		<category><![CDATA[rentalrundown]]></category>

		<guid isPermaLink="false">http://www.johnyerhot.com/?p=69</guid>
		<description><![CDATA[Two things&#8230;
First - Jen and I are taking a trip to Seattle for 7 days starting this Saturday.  We&#8217;re super pumped.  
Second &#8211; Over Christmas last year I started on this lil Rails app I was calling duluthrentalreview.com.  Pretty obvious what it was.  I get so pissed at landlords in this town, and even more pissed at [...]]]></description>
			<content:encoded><![CDATA[<p>Two things&#8230;</p>
<p>First - <a href="http://jen.yerhot.org">Jen</a> and I are taking a trip to Seattle for 7 days starting this Saturday.  We&#8217;re super pumped.  </p>
<p>Second &#8211; Over Christmas last year I started on this lil Rails app I was calling duluthrentalreview.com.  Pretty obvious what it was.  I get so pissed at landlords in this town, and even more pissed at my fellow renters for putting up with the crap quality of said rentals.  The problem is this:  Landlords in this town do not keep up their rentals because renters do not demand that they are nice and decent and that the landlords keep them up.  You get the idea. </p>
<p>Ok, so yeah I started writing this rental review site over christmas, got like halfway though it and just didn&#8217;t have time to finish it.. till now.  I re-wrote almost all of it, convertging it to REST.   I&#8217;m gonna try to continue updating it over the next couple days till our trip.  Oh, ad the url changed from duluthrentalreview.com to <a href="http://rentalrundown.com">rentalrundown.com</a>&#8230; liked the sound of <a href="http://rentalrundown.com">rentalrundown</a> better.</p>
<p> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnyerhot.com/2008/06/09/rentalrundowncom-and-seattle-trip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Super Simple Ruby Web Scraper</title>
		<link>http://www.johnyerhot.com/2008/05/19/anatomy-of-a-ruby-web-scraper/</link>
		<comments>http://www.johnyerhot.com/2008/05/19/anatomy-of-a-ruby-web-scraper/#comments</comments>
		<pubDate>Mon, 19 May 2008 19:47:37 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[mechanize]]></category>
		<category><![CDATA[open uri]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[sweefner.com]]></category>
		<category><![CDATA[web scraper]]></category>

		<guid isPermaLink="false">http://www.johnyerhot.com/2008/05/19/anatomy-of-a-ruby-web-scraper/</guid>
		<description><![CDATA[Alrighty folks.  Quick walk though for scraping remote web data with Ruby.  This is how I did it for my little web scraper I wrote on Saturday..
DISCLAIMER: Web Scraping is kind of a gray area.. don&#8217;t steal things that are copywritten and don&#8217;t be a jerk.  Give credit where credit is due..
First [...]]]></description>
			<content:encoded><![CDATA[<p>Alrighty folks.  Quick walk though for scraping remote web data with Ruby.  This is how I did it for my little web scraper I wrote on Saturday..</p>
<p><strong>DISCLAIMER:</strong> Web Scraping is kind of a gray area.. don&#8217;t steal things that are copywritten and don&#8217;t be a jerk.  Give credit where credit is due..</p>
<p>First thing is first.  You&#8217;ll need to install the <a href="http://mechanize.rubyforge.org/mechanize/">Mechanize</a> Ruby Gem.</p>
<blockquote><p>sudo gem install mechanize</p></blockquote>
<p>Mechanize is pretty slick.  It will iterate through a given url and let you access various html elements.  Further, you can use <a href="http://code.whytheluckystiff.net/hpricot/wiki">Hpricot</a> methods to further grab data.Lets get going..</p>
<blockquote><p>require &#8216;rubygems&#8217;require &#8216;mechanize&#8217;require &#8216;uri&#8217;</p>
<p>url = &#8220;http://www.johnyerhot.com&#8221;</p></blockquote>
<p>The way this is set up, you MUST have a complete url.</p>
<blockquote><p>@mech = WWW::Mechanize.new</p>
<p>@page = @mech.get(url)</p></blockquote>
<p>Now, lets say we want to get all the urls for embedded images from the webpage (http://www.johnyerhot.com)..</p>
<blockquote><p>@imgs = @page.search(&#8221;img[@src]&#8220;).map {|src| src['src']}</p></blockquote>
<p>You&#8217;ve now got an array (@imgs) with all the urls for embeded images!  What we actually did was use Hpricot&#8217;s search method to look for and image tags and sucked out the src attribute of that tag.  Mechanize does have its own methods for grabbing tags also, for example,  you can grab all the link targets from every link in the web page.</p>
<blockquote><p>#remember @page is just our mechanize instance<br />
# w/ http://www.johnyerhot.com</p>
<p>@links = Array.new<br />
@page.links.each do |link|<br />
@links &lt;&lt; link.href<br />
end</p></blockquote>
<p>Now lets weed out any links to non-images:</p>
<blockquote><p>@links.each do |link|  #yeah we&#8217;re only collecting jpgs</p>
<p>if (link.to_s.include? &#8220;.jpg&#8221;) || (link.to_s.include? &#8220;.JPG&#8221;) || (link.to_s.include? &#8220;.jpeg&#8221;) || (link.to_s.include? &#8220;.JPEG&#8221;)</p>
<p>@imgs &lt;&lt; link<br />
end<br />
end</p></blockquote>
<p>Finally, lets actually grab all those pictures and save them locally using Open URI&#8230;</p>
<blockquote><p>@counter =0<br />
@imgs.each do |image|<br />
url = URI.parse(image)#parse the url and separate need info<br />
Net::HTTP.start(url.host, url.port) { |http|<br />
#appeand the image path with the web root.<br />
image = http.get(image)#actually make the file to save<br />
open(&#8221;#{url.host}_#{counter}.jpg&#8221;, &#8220;wb&#8221;) { |file|<br />
file.write(image.body)<br />
counter = counter + 1<br />
}<br />
end</p></blockquote>
<p>And there you have it! Put it all together and you should have a functioning Ruby web scraper&#8230;Sort of. You still have to account for relative vs. absolute urls, are you gonna let in more than jpgs?, what if you need basic authentication for the url? There are still some missing pieces that need to be implemented to have this be ready for general use, but the core is there.<br />
<strong>Further Reading</strong><br />
<a href="http://mechanize.rubyforge.org/mechanize/">Mechanize Docs</a><br />
<a href="http://code.whytheluckystiff.net/hpricot">Hpricot</a><br />
<a href="http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/">Open URI</a><br />
<a href="http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html">Ruby net/http Docs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnyerhot.com/2008/05/19/anatomy-of-a-ruby-web-scraper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slicehost problems with Gem *FIXED*</title>
		<link>http://www.johnyerhot.com/2008/03/17/slicehost-problems-with-gem-fixed/</link>
		<comments>http://www.johnyerhot.com/2008/03/17/slicehost-problems-with-gem-fixed/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 18:43:33 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Slicehost]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[problems]]></category>

		<guid isPermaLink="false">http://www.johnyerhot.com/2008/03/17/slicehost-problems-with-gem-fixed/</guid>
		<description><![CDATA[Today I set up 470.johnyerhot.com and set up a Rails app I worked on to run there, but I needed to install the Pdf-writer Gem for proper functionality.  Low and behold when I tried
sudo gem install pdf-writer
I was greeted with nothing, just
Updating Gem source index for: http://gems.rubyforge.org
and that was it.  After searching and [...]]]></description>
			<content:encoded><![CDATA[<p>Today I set up 470.johnyerhot.com and set up a Rails app I worked on to run there, but I needed to install the Pdf-writer Gem for proper functionality.  Low and behold when I tried</p>
<blockquote><p>sudo gem install pdf-writer</p></blockquote>
<p>I was greeted with nothing, just</p>
<blockquote><p>Updating Gem source index for: http://gems.rubyforge.org</p></blockquote>
<p>and that was it.  After searching and searching I realized the the version of Gem I had installed was 0.94 and that was the problem.</p>
<p>The solution is as follows:</p>
<blockquote><p>wget http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz<br />
tar zxvf rubygems-1.0.1.tgz<br />
cd rubygems-1.0.1<br />
ruby setup.rb<br />
sudo gem update</p></blockquote>
<p>You just need to manually install the updated Gem. Cinch.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnyerhot.com/2008/03/17/slicehost-problems-with-gem-fixed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: Nginx, FCGI, PHP, MySQL, Ruby On Rails, Rewrite</title>
		<link>http://www.johnyerhot.com/2008/02/12/how-to-nginx-fcgi-php-mysql-ruby-on-rails-rewrite-vhosts/</link>
		<comments>http://www.johnyerhot.com/2008/02/12/how-to-nginx-fcgi-php-mysql-ruby-on-rails-rewrite-vhosts/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 17:25:56 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[FCGI]]></category>
		<category><![CDATA[Gutsy]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[MYSQL]]></category>
		<category><![CDATA[Rewrite]]></category>
		<category><![CDATA[Ubuntu 7.10]]></category>

		<guid isPermaLink="false">http://www.johnyerhot.com/2008/02/12/how-to-nginx-fcgi-php-mysql-ruby-on-rails-rewrite-vhosts/</guid>
		<description><![CDATA[
In a previous post I talked about how I just set up my new Slicehost account using Nginx to power this blog (Wordpress &#8211; PHP) and some Rails Apps.  Here&#8217;s a mini how to on how I got the whole thing working, as its not quite as easy as it sounds.
First though &#8211; Why [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.john.yerhot.org/posts/5-Debian-Etch-Nginx-Php-Php-Fpm-Ruby-MySQL"></a></p>
<p>In a previous post I talked about how I just set up my new Slicehost account using <a href="http://nginx.net/">Nginx</a> to power this blog (Wordpress &#8211; PHP) and some <a href="http://royner.johnyerhot.com">Rails Apps</a>.  Here&#8217;s a <span style="text-decoration: line-through;">mini</span> how to on how I got the whole thing working, as its not quite as easy as it sounds.</p>
<p>First though &#8211; Why not use <a href="http://www.apache.org/">Apache</a> + mod_proxy&#8230; There is a ton of documentation out there for Apache, and the majority of the web runs on it?</p>
<p>Well, Nginx is super tiny and super light weight and super fast.  If you are in a situation like many people who are using Slicehost and a 256 MB slice, Apache has too big a resource foot print.  If you are a Rails guy (or gal) Apache is just used as a proxy to send requests to Mongrel and Apache will just use resources that could be used else where.  Nginx is stable, well supported, and growing in popularity.  Plus the name is cool.. NGINX.. yeah&#8230;</p>
<p>This will (should) work with a fresh install of <a href="http://www.ubuntu.com/products/WhatIsUbuntu/serveredition">Ubuntu Server 7.10</a>, but as always YMMV.</p>
<p>A lot of this is adapted from a great post on <a href="http://www.howtoforge.com/nginx_php5_fast_cgi_xcache_ubuntu7.04">How To Forge</a>, thanks  <a title="View user profile." rel="nofollow" href="http://www.howtoforge.com/forums/member.php?u=23452">3uropa.</a></p>
<p>Install only the OpenSSH packages NOT the LAMP packages when installing Ubuntu Server 7.10.  You&#8217;ll have to setup networking for whatever your situation is so can&#8217;t help you there.  If you have a Slicehost slice, don&#8217;t do anything.  :)<br />
<a title="install ubuntu" href="http://www.johnyerhot.com/wp-content/uploads/2008/02/install_ubuntu.png"><img src="http://www.johnyerhot.com/wp-content/uploads/2008/02/install_ubuntu.png" alt="install ubuntu" /><br />
</a><a title="install ubuntu 2" href="http://www.johnyerhot.com/wp-content/uploads/2008/02/install_ubuntu_3.png"><img src="http://www.johnyerhot.com/wp-content/uploads/2008/02/install_ubuntu_3.png" alt="install ubuntu 2" /></a></p>
<p>Once that is finished installing Ubuntu Server, the first thing you want to do is update and get some prerequisites out of the way!</p>
<blockquote><p>sudo apt-get update<br />
sudo apt-get upgrade<br />
sudo apt-get install build-essential</p></blockquote>
<p>Ok.  Now, you need to go in and get all your files/directories in order.  That mean, go to /var/www/ (or wherever) and make directories for your PHP site.  In my case, I used /home/joyerhot/public_html/johnyerhot.com/wordpress as the root of my Wordpress blog.   You should be able to either use wget to grab stuff or SFTP in with your username and password.</p>
<p>Ok. Next we will install PHP5 and MySQL</p>
<blockquote><p>apt-get install php5-cli php5-cgi  build-essential mysql-server mysql-client libmysqlclitene15-dev</p></blockquote>
<p>Now, lets get Nginx while we&#8217;re at it!  The version that is in Ubuntu&#8217;s repos is old and not cool, so we&#8217;ll manually grab a newer version:</p>
<blockquote><p>wget http://technokracy.net/nginx/nginx_0.5.32~grrr-1_i386.deb<br />
sudo dpkg nginx_*</p></blockquote>
<p>And now Nginx is running and listening to port 8000.. we&#8217;ll change that later though.<br />
<a title="nginx setup" href="http://www.johnyerhot.com/wp-content/uploads/2008/02/nginx_setup.png"><img src="http://www.johnyerhot.com/wp-content/uploads/2008/02/nginx_setup.png" alt="nginx setup" /></a></p>
<p>Now, here is where it gets sticky.  You are going to create and edit /etc/nginx/sites-enabled/mysite</p>
<blockquote><p>sudo nano /etc/nginx/sites-enabled/mysite</p></blockquote>
<p>and put in it the following, changing directories and whatnot to what is appropriate for you.</p>
<blockquote><p>server {</p>
<p>listen   80;<br />
server_name yourdomain.com;<br />
rewrite ^/(.*) http://www.yourdomain.com permanent;</p>
<p>}</p>
<p>server {</p>
<p>listen   80;<br />
server_name www.yourdomain.com;</p>
<p>access_log /home/joyerhot/public_html/yourdomain.com/logs/access.log;<br />
error_log /home/joyerhot/public_html/yourdomain.com/logs/error.log;</p>
<p>if (!-e $request_filename) {<br />
rewrite ^([_0-9a-zA-Z-]+)?(/wp-.*) $2 last;<br />
rewrite ^([_0-9a-zA-Z-]+)?(/.*\.php)$ $2 last;<br />
rewrite ^ /index.php last;<br />
}</p>
<p>location / {</p>
<p>root   /home/joyerhot/public_html/johnyerhot.com/wordpress;<br />
index  index.html index.php index.htm;</p>
<p>}</p>
<p># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000<br />
#<br />
location ~ \.php$ {<br />
fastcgi_pass 127.0.0.1:9000;<br />
fastcgi_index index.php;<br />
fastcgi_param QUERY_STRING $query_string;<br />
fastcgi_param REQUEST_METHOD $request_method;<br />
fastcgi_param CONTENT_TYPE $content_type;<br />
fastcgi_param CONTENT_LENGTH $content_length;<br />
fastcgi_param SCRIPT_FILENAME /home/joyerhot/public_html/yourdomain.com/wordpress/$fastcgi_script_name;<br />
fastcgi_param REQUEST_URI $request_uri;<br />
fastcgi_param DOCUMENT_URI $document_uri;<br />
fastcgi_param DOCUMENT_ROOT $document_root;<br />
fastcgi_param SERVER_PROTOCOL $server_protocol;<br />
fastcgi_param GATEWAY_INTERFACE CGI/1.1;<br />
fastcgi_param SERVER_SOFTWARE nginx;<br />
fastcgi_param REMOTE_ADDR $remote_addr;<br />
fastcgi_param REMOTE_PORT $remote_port;<br />
fastcgi_param SERVER_ADDR $server_addr;<br />
fastcgi_param SERVER_PORT $server_port;<br />
fastcgi_param SERVER_NAME $server_name;<br />
}<br />
}</p></blockquote>
<p><a title="editing_nginx" href="http://www.johnyerhot.com/wp-content/uploads/2008/02/eding_nginx.png"><img src="http://www.johnyerhot.com/wp-content/uploads/2008/02/eding_nginx.png" alt="editing_nginx" /></a></p>
<p>WHEW!  There is A LOT of stuff there!  This will setup a Virtual Host for your PHP site, and enable rewrites (for pretty urls).  Here is what you need to change in yours though:</p>
<p>1. the server_name is whatever your domain is.<br />
2. rewrite ^/(.*) http://www.whatever_goes_here.com permanent;<br />
3. access_log directory<br />
4. error_log directory<br />
5. root directory<br />
6. fastcgi_param SCRIPT_FILENAME /path/to/your/php/app/root/$fastcgi_script_name;<br />
7. MAKE SURE YOU&#8217;RE LISTENING TO PORT 80.</p>
<p>Ok, now we&#8217;ll get PHP5 working as a fcgi process.  To do this, we need to grab some of Lighttpd.</p>
<blockquote><p>wget http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2<br />
tar -xvjf lighttpd-*<br />
cd lighttpd*<br />
./configure<br />
make</p></blockquote>
<p>DO NOT &#8220;make install&#8221;.  :)</p>
<blockquote><p>sudo cp src/spawn-fcgi /usr/bin/spawn-fcgi<br />
sudo nano /usr/bin/php-fastcgi</p></blockquote>
<p>Now, add the following into php-fastcgi:</p>
<blockquote><p>/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 2 -u www-data -f /usr/bin/php5-cgi</p></blockquote>
<p>-C controls how many fcgi instances of PHP5 are spawned, so you can put however many are appropriate for you in there.  I only needed 2.</p>
<blockquote><p>sudo nano /etc/init.d/init-fastcgi</p></blockquote>
<p>And add:</p>
<blockquote><p>#!/bin/bash<br />
PHP_SCRIPT=/usr/bin/php-fastcgi<br />
RETVAL=0<br />
case &#8220;$1&#8243; in<br />
start)<br />
$PHP_SCRIPT<br />
RETVAL=$?<br />
;;<br />
stop)<br />
killall -9 php<br />
RETVAL=$?<br />
;;<br />
restart)<br />
killall -9 php<br />
$PHP_SCRIPT<br />
RETVAL=$?<br />
;;<br />
*)<br />
echo &#8220;Usage: php-fastcgi {start|stop|restart}&#8221;<br />
exit 1<br />
;;<br />
esac<br />
exit $RETVAL</p></blockquote>
<p>Do some permission magic:</p>
<blockquote><p>sudo chmod 755 /etc/init.d/init-fastcgi<br />
sudo chmod 755 /usr/bin/php-fastcgi</p></blockquote>
<p>Now, you can make sure everything is working by:</p>
<blockquote><p>/etc/init.d/init-fastcgi start<br />
top #then shift + M</p></blockquote>
<p>You should see a couple of PHP5 fcgi processes! YAY!<br />
Finally, we want them to start on reboots and whatnot so&#8230;</p>
<blockquote><p>update-rc.d init-fastcgi defaults</p></blockquote>
<p>Ok, now lets restart Nginx and see if things are working!</p>
<blockquote><p>/etc/init.d/nginx restart</p></blockquote>
<p>You should be able to hit your Php app now!</p>
<p>Now for Ruby and friends!</p>
<blockquote><p>sudo apt-get install libmysql-ruby1.8 ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15-dev libmysqlclient15off libnet-daemon-perl libopenssl-ruby libopenssl-ruby1.8 libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client mysql-client-5.0 mysql-common mysql-server mysql-server-5.0 rdoc1.8 ri1.8 ruby1.8 ruby1.8-dev zlib1g-dev</p></blockquote>
<p>And you might need to create some symlinks (I had to), thanks <a href="http://www.urbanpuddle.com/articles/2008/01/09/install-ruby-on-rails-on-ubutu-gutsy-gibbon-apache-version">Vince Wadhwanl</a>.</p>
<blockquote><p>sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby<br />
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc<br />
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri<br />
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb</p></blockquote>
<p>Make sure things are working ok&#8230;</p>
<blockquote><p>ruby -v</p></blockquote>
<p>You should get that you have 1.8.6 installed.Ok, now lets install RubyGems.</p>
<blockquote><p>wget http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz<br />
tar xvzf rubygems-1.0.1.tgz<br />
cd rubygems-1.0.1<br />
sudo ruby setup.rb<br />
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem</p></blockquote>
<p>And finally for Rails and Mongrel:</p>
<blockquote><p>sudo gem install rails<br />
sudo gem install mongrel mongrel_cluster</p></blockquote>
<p>You can now set up a mongrel_cluster or whatever you need.  There&#8217;s plenty of tutorials out there for that, so <a href="http://www.google.com/search?hl=en&amp;q=mongrel_cluster+ubuntu&amp;btnG=Google+Search">Google</a> is your friend.   The rest will assume you have your Rails app up and running on port 3000.<br />
We now have to set up a site profile for Nginx for your mongrel_cluster.</p>
<blockquote><p>sudo nano /etc/nginx/sites-enabled/rails_app</p></blockquote>
<p>And add to it, once again changing the relevant parts&#8230;.</p>
<blockquote><p>upstream domain1 {<br />
server 127.0.0.1:3000;<br />
}</p>
<p>server {</p>
<p>listen   80;<br />
server_name  www.your2nddomain.com;<br />
rewrite ^/(.*) http://subdomain.your2nddomain.com permanent;</p>
<p>}</p>
<p>server {</p>
<p>listen   80;<br />
server_name subdomain.your2nddomain.com;</p>
<p>access_log /home/joyerhot/public_html/your2nddomain.com/logs/access.log;<br />
error_log /home/joyerhot/public_html/your2nddomain.com/logs/error.log;</p>
<p>location / {</p>
<p>root   /home/joyerhot/public_html/your2nddomain.com/public/RAILS_ROOT/public/;<br />
index  index.html;<br />
location / {<br />
proxy_set_header  X-Real-IP  $remote_addr;<br />
proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;<br />
proxy_set_header Host $http_host;<br />
proxy_redirect false;</p>
<p>if (-f $request_filename/index.html) {<br />
rewrite (.*) $1/index.html break;<br />
}</p>
<p>if (-f $request_filename.html) {<br />
rewrite (.*) $1.html break;<br />
}</p>
<p>if (!-f $request_filename) {<br />
proxy_pass http://domain1;<br />
break;<br />
}<br />
}</p>
<p>}</p>
<p>}</p></blockquote>
<p>Again, heres what you need to change:<br />
1. server_name should be the domain<br />
2. In this case the &#8220;rewrite&#8221; line will point to subdomain.your2nddomain.com, you should prolly just put your domain here(www.your2nddomain.com).<br />
3. access_log directory<br />
4. error_log directory<br />
5. root directory (pointing to RAILS_ROOT/public)</p>
<p>That&#8217;s it!  You should now restart Nginx (/etc/init.d/nginx restart) and when you should have everything working!   You&#8217;ve got Virtual Hosts setup with PHP running as Fast CGI on one domain and Ruby On Rails on the other!</p>
<p>I&#8217;m sure I&#8217;ve got a typo or two in here and a mistake here and there, please leave a message if this worked or didn&#8217;t work for you.  Remember, this is the process I went through getting everything working on my Slicehost Slice and another server at work, both running Ubuntu 7.10.</p>
<p><strong>PS</strong>.  Here is one little nugget of info that may be helpful &#8211; Your MySQL socket file location (for your RAILS_ROOT/config/database.yml file) is located at /var/run/mysqld/mysqld.sock.  I didn&#8217;t realize this at first.  :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnyerhot.com/2008/02/12/how-to-nginx-fcgi-php-mysql-ruby-on-rails-rewrite-vhosts/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Debugging Backgroundrb</title>
		<link>http://www.johnyerhot.com/2008/02/11/debugging-backgroundrb/</link>
		<comments>http://www.johnyerhot.com/2008/02/11/debugging-backgroundrb/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 17:34:20 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[backgroundrb]]></category>
		<category><![CDATA[mongrel]]></category>
		<category><![CDATA[top]]></category>

		<guid isPermaLink="false">http://www.johnyerhot.com/2008/02/11/debugging-backgroundrb/</guid>
		<description><![CDATA[Backgroundrb is a great tool for getting cron like functionality in your Rails app, but it can be a pain if its not working correctly.  I&#8217;m not going to go into how to get backgroundrb working, its rubyforge page has decent instructions for that, but what I will share are some tips on debugging [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://backgroundrb.rubyforge.org/">Backgroundrb</a> is a great tool for getting <a href="http://en.wikipedia.org/wiki/Crontab">cron</a> like functionality in your Rails app, but it can be a pain if its not working correctly.  I&#8217;m not going to go into how to get backgroundrb working, <a href="http://backgroundrb.rubyforge.org/">its rubyforge page</a> has decent instructions for that, but what I will share are some tips on debugging a non-working worker.</p>
<p>Obviously check your RAILS_ROOT/log and check backgroundrb.log, backgroundrb_server.log, and backgroundrb_debug.log.  I&#8217;ve found backgroundrb.log most useful, but many times I&#8217;ll restart backgroundrb by</p>
<blockquote><p> script/backgroundrb stop</p>
<p>script/backgroundrb  start #restart doesn&#8217;t work for me</p></blockquote>
<p>and nothing will happen.  Check your backgroundrb_server.log file and you may see that the &#8216;address is already in use&#8221;.</p>
<p>Type &#8220;top&#8221; into your command line (on a Linux system) and then press shift+M.  You should get a nice list of services running and you&#8217;ll more than likely have a couple of rubys on there.  For some reason backgroundrb doesn&#8217;t stop all the time when you tell it to and I&#8217;ve had to kill -9 the rubys and then restart backgroundrb and mongrel.</p>
<p>You may also notice that the backgroundrb ruby instance uses ALOT of memory!  Make sure you have</p>
<blockquote><p> :environment: production</p></blockquote>
<p>in your backgroundrb.yml file in RAILS_ROOT/config.  Otherwise backgroundrb is working in development mode.</p>
<p>Finally, to debug an syntax or other error try this.</p>
<p>1. open 2 command lines.</p>
<p>2. start your rails app with ruby script/server.  Make sure to start it in development mode and not using mongrel_rails.</p>
<p>3. start backgroundrb in the other terminal.</p>
<p>4. watch the first terminal and you can see what background rb is doing and where exactly it gets messed up.</p>
<p>You can do this by monitoring the log file or tailing it, but I like this better and it provides you with more info.</p>
<p>Hope this helps any of you out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnyerhot.com/2008/02/11/debugging-backgroundrb/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Moved Hosts</title>
		<link>http://www.johnyerhot.com/2008/02/01/moved-hosts/</link>
		<comments>http://www.johnyerhot.com/2008/02/01/moved-hosts/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 06:04:01 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Royner]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Slicehost]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[godaddy]]></category>
		<category><![CDATA[ocssolutions]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://www.johnyerhot.com/2008/02/01/moved-hosts/</guid>
		<description><![CDATA[Well I&#8217;ve finished consolodating my two hosting accounts, one at Godaddy (cheap Linux hosting) and my shared Rails hosting at OcsSolutions (which was very good for shared Rails host) to a 512 mb Ubuntu 7.10 &#8217;slice&#8217; at Slicehost.  Was gonna go straight Debian, but figured what the hell.  For any of you who don&#8217;t know, [...]]]></description>
			<content:encoded><![CDATA[<p>Well I&#8217;ve finished consolodating my two hosting accounts, one at Godaddy (cheap Linux hosting) and my shared Rails hosting at <a href="http://www.ocssolutions.com/">OcsSolutions</a> (which was very good for shared Rails host) to a 512 mb Ubuntu 7.10 &#8217;slice&#8217; at <a href="http://www.slicehost.com">Slicehost</a>.  Was gonna go straight Debian, but figured what the hell.  For any of you who don&#8217;t know, a &#8217;slice&#8217; is pretty much get VPS hosting account.  This is my first VPS.  I set up Apache/Rails proxy servers and your run of the mill LAMP servers for customers/clients and at work all the time, but this is MY first server that is all mine to mess with.</p>
<p>As mentioned, I decided to give <a href="http://nginx.net/">Nginx</a> a try. I have to admit, initial set up is very easy.  I first setup the Rails enviornment and had Nginx proxy to two mongrels for each app.  (I&#8217;m running two apps for four total Mongrels).  No problem.</p>
<p>Next, I had to get php working.  Not so easy.</p>
<p>I ended up looking for help and followed <a href="http://www.howtoforge.com/nginx_php5_fast_cgi_xcache_ubuntu7.04">this,</a> setting up php5 to run as fast-cgi.  Ugh.  To make things worse, I had to move over the Wordpress install from Godaddy.  I assummed it would be easy as pie, and it was to an extent, but I ran into trouble with the way the virtual hosts configs nginx uses handle subdomains and .. long story short I had redirect loop happening and it just sucked.</p>
<p>I&#8217;m blabering on and on here, but in the end I&#8217;ve got everything up and running.  We&#8217;ll see how Nginx works in the long term, but right now it seems pretty snappy and the memory footprint is much smaller than Apache.</p>
<p>So, Royner and another project of mine have a place to live and I&#8217;m just gonna do some final tweaks this weekend and then you can check them out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnyerhot.com/2008/02/01/moved-hosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails: Using Helpers in Your Controller.</title>
		<link>http://www.johnyerhot.com/2008/01/10/rails-using-helpers-in-you-controller/</link>
		<comments>http://www.johnyerhot.com/2008/01/10/rails-using-helpers-in-you-controller/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 15:40:15 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Controller]]></category>
		<category><![CDATA[Helpers]]></category>
		<category><![CDATA[pdf-writer]]></category>

		<guid isPermaLink="false">http://www.johnyerhot.com/2008/01/10/rails-using-helpers-in-you-controller/</guid>
		<description><![CDATA[This morning there was a guy in the rails IRC room asking about using helpers in his controller and I recently wrote an app that used the great pdf-writer gem to generate some pdfs and used helpers in the controller for formatting in the pdf.  If you are going to generate very complicated pdfs, [...]]]></description>
			<content:encoded><![CDATA[<p>This morning there was a guy in the rails IRC room asking about using helpers in his controller and I recently wrote an app that used the great <a href="http://ruby-pdf.rubyforge.org/pdf-writer/" target="_blank">pdf-writer</a> gem to generate some pdfs and used helpers in the controller for formatting in the pdf.  If you are going to generate very complicated pdfs, its best not to put your pdf formatting code directly in the controller, but if you need just a real quick pdf generated, this works great.</p>
<p>First, create a new class in your application controller:<br />
<code><br />
class Helper<br />
include Singleton<br />
include ActionView::Helpers::PdfHelper #or whatever helpers you want<br />
end<br />
</code><br />
I wanted to use my pdf_helpers<br />
..and then:<br />
<code><br />
def pdf_helpers<br />
Helper.instance<br />
end</code><br />
Will create an instance of your new class.</p>
<p>Now, go to your pdf controller (or whatever) and simply:<br />
<code><br />
pdf.text pdf_helpers.my_crazy_helper(@foo.bar)<br />
</code></p>
<p>The pdf.text part is not the important part, thats just for pdf-writer, but what is is using &#8220;pdf_helpers.your_helper&#8221; to create a new instance of the helper class which will allow you to use that helper.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnyerhot.com/2008/01/10/rails-using-helpers-in-you-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
