<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Rails Rant</title>
	<atom:link href="http://railsrant.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://railsrant.com</link>
	<description>My experience with Rails, Mongrel, Nginx, MySQL, etc..</description>
	<lastBuildDate>Wed, 10 Mar 2010 20:58:39 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='railsrant.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/f4233c59f814634238651db364b4314f?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Rails Rant</title>
		<link>http://railsrant.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://railsrant.com/osd.xml" title="Rails Rant" />
	<atom:link rel='hub' href='http://railsrant.com/?pushpress=hub'/>
		<item>
		<title>Ruby Module Mixin Awesomeness</title>
		<link>http://railsrant.com/2010/03/10/ruby-module-mixin-awesomeness/</link>
		<comments>http://railsrant.com/2010/03/10/ruby-module-mixin-awesomeness/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 20:57:57 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=169</guid>
		<description><![CDATA[The deeper I dig into Rails, the more I need to know about Ruby.  I have been learning more about how Ruby does OO.  I came to Ruby from Java and at first things like modules were confusing for me.  Recently I discovered the power of mixin modules.  I was trying to figure out how [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=169&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>The deeper I dig into Rails, the more I need to know about Ruby.  I have been learning more about how Ruby does OO.  I came to Ruby from Java and at first things like modules were confusing for me.  Recently I discovered the power of mixin modules.  I was trying to figure out how to put my models into a plugin and then override or add additional functionality to those models.  My main reason for doing this was to change the database referenced in the &#8220;use_db&#8221; plugin.  I had a hard time finding an elegant way to do it, but mixin modules really helped me do it in simple way.</p>
<p>So what do mixin modules do?  Basically they allow you to code instance methods into a module and then include the module in a class.  The class will then have access to the instance methods in a module.  Pretty nice when you have shared functionality between models.  You can code one module and include it in several models.</p>
<p>Here is an example:</p>
<div style="border:1px solid #aaa;background-color:#eee;padding:10px;">
<pre>module LoudModule
  def explode
    "BOOM!"
  end
end

class BottleRocket
  include LoudModule
end

class FireCracker
  include LoudModule
end

firecracker = FireCracker.new
p firecracker.explode

bottlerocket = BottleRocket.new
p bottlerocket.explode
</pre>
</div>
<p>As you can see firecracker and bottlerocket both have access to the &#8220;explode&#8221; instance method in the module.</p>
<p>Now to make this work with a Rails plugin where you need a model base class:</p>
<div style="border:1px solid #aaa;background-color:#eee;padding:10px;">
<pre>module BaseWidget
  self.included?(base)
    base.belongs_to :manufacturer
  end

  def some_instance_method
    "test"
  end
end

class Widget &lt; ActiveRecord::Base
  unloadable
  use_db :prefix =&gt; "mydatabse_prefix_"
  include BaseWidget
  def some_new_instance_method
    "test2"
  end
end
</pre>
</div>
<p>This is pretty cool because it will allow you to define a base class for your model that you can reuse in different applications.  The self.included? block allows you to load use the instance methods from the base class (ActiveRecord::Base in this case).  So Widget will have access to all the associations, named_scopes and act_as* methods from the Base class.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/169/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/169/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/169/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=169&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2010/03/10/ruby-module-mixin-awesomeness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting up a Ruby on Rails stack on Rackspace Cloud</title>
		<link>http://railsrant.com/2010/03/10/setting-up-a-ruby-on-rails-stack-on-rackspace-cloud/</link>
		<comments>http://railsrant.com/2010/03/10/setting-up-a-ruby-on-rails-stack-on-rackspace-cloud/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 16:30:19 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Mongrel]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=144</guid>
		<description><![CDATA[I have been using Rackspace Cloud for several months and it is the most advanced web hosting I have ever seen by a long shot.   Rackspace has always had great customer service, but I always thought the pricing was ridiculous compared to similar options.  Not anymore.. with the Cloud you can get a cheap, flexible [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=144&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I have been using <a title="Rackspace Cloud" href="http://rackspacecloud.com">Rackspace Cloud</a> for several months and it is the most advanced web hosting I have ever seen by a long shot.   Rackspace has always had great customer service, but I always thought the pricing was ridiculous compared to similar options.  Not anymore.. with the Cloud you can get a cheap, flexible and scalable solution (I&#8217;m still keeping an eye on reliability.. time will tell).  Currently I have 9 servers running on the cloud, but I am still waiting to move my flagship site to the cloud..  reliability and performance seem great so far, but I want to give it a few more months before I commit my highest traffic site to it.  Its pretty easy to get a Rails stack running on the cloud using a simple shell script.  Here is what I am currently using.  Note that some of the versions may be outdated when you read this article, so you may need to update the script.  Once you have this server loaded, you can create a backup and then create more servers based on that backup.  You can literally have a working dedicated Rails server in less than 5 minutes.  I am using a CentOS 5.4 server on the cloud</p>
<p>Server setup shell script:  setup.sh</p>
<div style="border:1px solid #aaa;background-color:#eee;padding:10px;">##############<br />
#  SETUP.SH  #<br />
##############</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# INSTALL SOFTWARE AND DEPENDENCIES WITH YUM<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm<br />
yum -y install mysql mysql-server mysql-devel gcc make zlib zlib-devel openssl openssl-devel git expect pcre pcre-devel readline-devel libxml2-devel libxslt-devel</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# CREATE A DIRECTORY FOR DOWNLOADED FILES AND INSTALL RUBY<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
mkdir /home/Downloads<br />
cd /home/Downloads<br />
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz<br />
tar -xvf ruby-1.8.7-p174.tar.gz<br />
cd ruby-1.8.7-p174<br />
./configure<br />
make<br />
make install</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
# INSTALL RUBYGEMS<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
cd ..<br />
wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz<br />
tar -xvf rubygems-1.3.5.tgz<br />
cd rubygems-1.3.5<br />
ruby setup.rb<br />
cd /</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# INSTALL GEMS &#8211; YOU WILL NEED RAILS, MONGREL AND PROBABLY MYSQL.<br />
# THE OTHERS ARE JUST SOME COMMON ONES I USE.<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
gem install &#8211;no-rdoc &#8211;no-ri rails -v=2.3.2<br />
gem install &#8211;no-rdoc &#8211;no-ri mime-types<br />
gem install &#8211;no-rdoc &#8211;no-ri mysql &#8212; &#8211;with-mysql-lib=/usr/lib64/mysql<br />
gem install &#8211;no-rdoc &#8211;no-ri fastercsv<br />
gem install &#8211;no-rdoc &#8211;no-ri mongrel mongrel_cluster<br />
gem install &#8211;no-rdoc &#8211;no-ri json<br />
gem install &#8211;no-rdoc &#8211;no-ri mechanize</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# CHANGE MYSQL TO STARTUP SCRIPT AND START SERVER<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
mv /etc/rc3.d/K36mysqld /etc/rc3.d/S36mysqld<br />
/etc/init.d/mysqld start</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# INSTALL NGINX WEB SERVER &amp; copy a working config file (you create this) to the config dir<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
wget http://sysoev.ru/nginx/nginx-0.7.64.tar.gz<br />
tar -xvf nginx-0.7.64.tar.gz<br />
cd nginx-0.7.64<br />
./configure &#8211;sbin-path=/sbin/nginx &#8211;conf-path=/usr/local/nginx/nginx.conf &#8211;pid-path=/usr/local/nginx/nginx.pid &#8211;with-http_ssl_module &#8211;with-md5=auto/lib/md5 &#8211;with-sha1=auto/lib/sha1<br />
make<br />
make install<br />
# THIS IS A DEFAULT NGINX CONFIG THAT I UPLOAD TO THE SERVER.  COPY NGINX CONFIG TO THE APPROPRIATE DIR &amp; RESTART<br />
cp /root/nginx.conf /usr/local/nginx/nginx.conf<br />
/sbin/nginx</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# OPEN UP SECURITY FOR MONGREL<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
echo 1 &gt;/selinux/enforce<br />
/usr/sbin/setsebool -P httpd_can_network_connect=1</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# OPTIONAL &#8211; SECURITY &#8211; THIS IS A DEFAULT IPTABLES SCRIPT I UPLOAD TO THE SERVER.  COPY IPTABLES SCRIPT OVER<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
cp /root/iptables_config /etc/sysconfig/iptables<br />
/etc/init.d/iptables restart</p>
<p>#*******************************************************************************************************<br />
# NOTE: THE REST OF THIS SCRIPT IS USED TO AUTOMATE PULLING YOUR APP CODE FROM GITHUB,<br />
# RAKING THE DB, AND ADDING STARTUP SCRIPTS FOR MONGREL, AND STARTING MONGREL INSIDE<br />
# YOUR RAILS APP DIR.  IF YOU ARE USING CAPISTRANO, SOME OF THIS IS PROBABLY NOT NECCESSARY, BUT I<br />
# HAVE BEEN TOO LAZY TO LEARN CAP.. THIS METHOD WORKS FINE FOR WHAT I DO<br />
#*******************************************************************************************************</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# OPTIONAL &#8211; CREATE RAILS DIR.. I ALWAYS USE THIS DIRECTORY.. MODIFY TO YOUR TASTE-&gt; /RAILS_APPS<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
mkdir rails_apps</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# OPTIONAL &#8211; IF YOU ARE USING GITHUB, YOU WILL WANT TO COPY YOUR SSH KEYS.<br />
# I JUST FTP THE KEY FILES TO MY SERVER ALONG WITH THE SETUP SCRIPT.<br />
# I PLACE ALL THE FILES I AM USING IN /ROOT/<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
mkdir /root/.ssh<br />
cp /root/id_rsa.pub /root/.ssh/id_rsa.pub<br />
cp /root/id_rsa /root/.ssh/id_rsa<br />
cp /root/known_hosts /root/.ssh/known_hosts<br />
chmod 700 /root/.ssh/*</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# OPTIONAL &#8211; GET THE APP FROM GITHUB<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
cd /rails_apps<br />
git clone git@github.com:yourusername/yourproject.git<br />
mkdir /rails_apps/yourproject/log<br />
mkdir /rails_apps/yourproject/tmp/pids</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# OPTIONAL &#8211; RAKE THE DB<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
cd /rails_apps/yourapp<br />
rake db:migrate</p>
<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
# OPTIONAL &#8211; ADD MONGREL STARTUP SCRIPT AND PUT IN RC.LOCAL AND START MONGREL<br />
#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
cp /root/server_start.sh /rails_apps/server_start.sh<br />
chmod 700 /rails_apps/*.sh<br />
echo &#8220;/rails_apps/start_server.sh&#8221; &gt;&gt; /etc/rc.local<br />
/rails_apps/server_start.sh</p>
</div>
<p>This worked for me last time I tried it. YMMV</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/144/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/144/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/144/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=144&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2010/03/10/setting-up-a-ruby-on-rails-stack-on-rackspace-cloud/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>
	</item>
		<item>
		<title>Installing memcached and using memcached with Rails on CentOS 5.x</title>
		<link>http://railsrant.com/2010/02/24/installing-memcached-and-using-memcached-with-rails-on-centos-5-x/</link>
		<comments>http://railsrant.com/2010/02/24/installing-memcached-and-using-memcached-with-rails-on-centos-5-x/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 15:04:11 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=153</guid>
		<description><![CDATA[Memcached is a great way to speed up your rails app using caching.  One great feature I like is that you can set the cache expiration date.  Great for pages or code blocks that only update every day, hour, etc..
I am installing this on a clean, stripped-down version of CentOS on Rackspace cloud.  So first [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=153&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Memcached is a great way to speed up your rails app using caching.  One great feature I like is that you can set the cache expiration date.  Great for pages or code blocks that only update every day, hour, etc..</p>
<p>I am installing this on a clean, stripped-down version of CentOS on Rackspace cloud.  So first things first, you need to install a c compiler and make</p>
<pre>&gt;yum install gcc</pre>
<pre>&gt;yum install make</pre>
<p>Next you need to install libevent</p>
<pre>&gt; wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz</pre>
<pre>&gt; tar -xvf libevent-1.4.13-stable.tar.gz</pre>
<pre>&gt; cd libevent-1.4.13-stable</pre>
<pre>&gt;./configure &amp;&amp; make</pre>
<pre>&gt; make install</pre>
<p>Good to go.. now you will need to download and install memcached</p>
<pre>&gt; cd ..</pre>
<pre>&gt; wget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz
&gt; tar -xvf memcached-1.4.4.tar.gz
&gt; cd memcached-1.4.4
&gt; ./configure &amp;&amp; make
&gt; make install</pre>
<p>Now you can start memcached</p>
<pre>&gt; /usr/local/bin/memcached -u nobody &amp;</pre>
<p>I also add this command (without the &#8216;&amp;&#8217; at the end) to /etc/rc.local, so memcached starts automatically if the server is rebooted</p>
<p>When you start memcached you may get the following error:</p>
<p><span style="color:#ff0000;">/usr/local/bin/memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory</span></p>
<p><span style="color:#ff0000;"><span style="color:#000000;">Here is the fix:</span></span></p>
<p><span style="color:#ff0000;"><span style="color:#000000;">Create this file<br />
</span></span></p>
<pre><span style="color:#ff0000;"><span style="color:#000000;">&gt; </span></span>nano /etc/ld.so.conf.d/libevent-i386.conf</pre>
<p>add the following line to the file and close and save it:</p>
<pre>/usr/local/lib/</pre>
<p>then run this command</p>
<pre>&gt; /sbin/ldconfig</pre>
<p>You should be able to start memcached now without the error</p>
<pre>&gt;/usr/local/bin/memcached -u nobody &amp;</pre>
<p>You can get the status like this if you have &#8216;nc&#8217; installed (yum install nc, if not)</p>
<pre>&gt; echo stats | nc 127.0.0.1 11211</pre>
<p><span style="text-decoration:line-through;"> </span></p>
<p>Memcached is now installed and working correctly.  Do the following to configure your rails app to work with it.  On the server that contains your Rails code:</p>
<pre>&gt; gem install memcache-client</pre>
<p>Uncomment or add this line to /your-rails-app/config/environments/production.rb</p>
<pre><span style="color:#ff0000;">config.cache_store = :mem_cache_store</span></pre>
<p><span style="color:#ff0000;"><span style="color:#000000;">Add caching code to your rails app.  For example you could cache an action in the ProductsController like this:</span></span></p>
<pre>class ProductsController &lt; ApplicationController
   caches_action :some_action, :expires_in =&gt; 1.hour
   ...
end

restart your rails app and you should be good to go
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/153/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=153&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2010/02/24/installing-memcached-and-using-memcached-with-rails-on-centos-5-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>
	</item>
		<item>
		<title>More named_scope stuff.  Chaining a named scope to a normal Rails find method</title>
		<link>http://railsrant.com/2010/02/24/more-named_scope-stuff-chaining-a-named-scope-to-a-normal-rails-find-method/</link>
		<comments>http://railsrant.com/2010/02/24/more-named_scope-stuff-chaining-a-named-scope-to-a-normal-rails-find-method/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 13:53:58 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=150</guid>
		<description><![CDATA[I had the problem recently where I was using a slave database on a website that is similar to another one, but has some differences in the data that needed to be displayed.  In order to display the correct data, I have to use a flag in one table that tells me whether the data [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=150&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I had the problem recently where I was using a slave database on a website that is similar to another one, but has some differences in the data that needed to be displayed.  In order to display the correct data, I have to use a flag in one table that tells me whether the data can be displayed on the secondary website (that uses the slave database).  Instead of adding to the conditions of every find I have, I decided to create a named scope with the condition in there, like so:</p>
<p>named_scope :filter_non_secondary_website_data, :conditions=&gt;&#8221;secondary_website=1&#8243;</p>
<p>I know you can chain named_scopes to each other, but I was wondering if I could chain it to a find method also.  At first I appending it to the end of a find like this</p>
<p><span style="color:#ff0000;">records = SomeModel.find(:all,:conditions=&gt;&#8221; you=&#8217;awesome&#8217; &#8220;)<strong>.filter_non_secondary_website_data</strong></span></p>
<p>Nope that didnt work.  If I remember the error was something about that method not existing for type array.  In order to make this work you need to append it to the beginning so the find can combine it with its SQL.  Here is the correct way which will append the SQL &#8220;AND secondary_website=1&#8243; to the find&#8217;s SQL</p>
<p><span style="color:#008000;">records = SomeModel<strong>.filter_non_secondary_website_data</strong>.find(:all,:conditions=&gt;&#8221; you=&#8217;awesome&#8217; &#8220;)</span></p>
<p><span style="color:#008000;"><span style="color:#000000;">That works.  There is probably a way I could override the find method in the model and add this code.  Anybody know??  I just searched my project for all finds and added the method.  Not exactly an optimal solution if you have a hundred finds.. but anyways, pretty cool that you can chain a named scope to find if you need to.</span><br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/150/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/150/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/150/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=150&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2010/02/24/more-named_scope-stuff-chaining-a-named-scope-to-a-normal-rails-find-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>
	</item>
		<item>
		<title>Space below an image when padding and margin are set to 0</title>
		<link>http://railsrant.com/2010/02/24/space-below-an-image-when-padding-and-margin-are-set-to-0/</link>
		<comments>http://railsrant.com/2010/02/24/space-below-an-image-when-padding-and-margin-are-set-to-0/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 13:39:34 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=147</guid>
		<description><![CDATA[I spent over an hour trying to figure this out, which was way too long, so I thought I would post the solution here.  The problem was that I had 2 images that we supposed to sit on top of each other vertically with no space or padding between them.  I set the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=147&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I spent over an hour trying to figure this out, which was way too long, so I thought I would post the solution here.  The problem was that I had 2 images that we supposed to sit on top of each other vertically with no space or padding between them.  I set the div that contains them to the same width as the image and specified float:left and margin/padding to be 0 as you can see in the code below.  I was still getting a few pixels of vertical space between the 2 images.  I messed around in firebug for an hour changing styles adding another div around the image, etc.. but nothing worked. Finally I stumbled upon a site that explained that FF and IE will put vertical spacing between images automatically.  You need to specify the display property on the image as block if you want to remove this.  I added <span style="color:#ff0000;"><strong>display:block</strong></span> to the code and it worked.  Vertical image spacing removed in Firefox and IE!</p>
<pre>&lt;div style="margin: 0pt; padding: 0pt; float: left; width: 150px;"&gt;
  &lt;img style="margin: 0pt; padding: 0pt; width: 150px; float: left;<span style="color:#ff0000;"><strong>display:block;</strong></span>" src="some-image.gif" alt="" /&gt;
  &lt;img style="margin: 0pt; padding: 0pt; width: 150px; float: left;<span style="color:#ff0000;"><strong>display:block;</strong></span>" src="some-image.gif" alt="" /&gt;
&lt;/div&gt;
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/147/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/147/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/147/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=147&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2010/02/24/space-below-an-image-when-padding-and-margin-are-set-to-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>
	</item>
		<item>
		<title>Create database from the command line or shell script</title>
		<link>http://railsrant.com/2009/11/23/create-database-from-the-command-line-or-shell-script/</link>
		<comments>http://railsrant.com/2009/11/23/create-database-from-the-command-line-or-shell-script/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 02:03:31 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=142</guid>
		<description><![CDATA[I am writing a shell script that to setup my server and I need to create a database as part of this process.  Its pretty easy to do.  You can create a database from the command line without logging in to mysql interactive mode.  Here is the code
&#62;mysql -u root -pyourpassword -e &#8220;create database some_database_name;&#8221;
NOTE: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=142&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I am writing a shell script that to setup my server and I need to create a database as part of this process.  Its pretty easy to do.  You can create a database from the command line without logging in to mysql interactive mode.  Here is the code</p>
<p>&gt;mysql -u root -pyourpassword -e &#8220;create database some_database_name;&#8221;</p>
<p>NOTE:  when I pasted this into bash, I had to change the quotes.. I guess wordpress converts them to a different encoding</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=142&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2009/11/23/create-database-from-the-command-line-or-shell-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>
	</item>
		<item>
		<title>Retrying MySQL slave query after an error</title>
		<link>http://railsrant.com/2009/11/19/retrying-mysql-slave-query-after-an-error/</link>
		<comments>http://railsrant.com/2009/11/19/retrying-mysql-slave-query-after-an-error/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 04:34:37 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=138</guid>
		<description><![CDATA[I did something stupid today.  I was logged into my slave and thought I was logged into the master.  I altered a table and then realized I was on the wrong server.  So I logged into master and altered the same table.  This created an error when the slave tried to replicate, because the column [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=138&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I did something stupid today.  I was logged into my slave and thought I was logged into the master.  I altered a table and then realized I was on the wrong server.  So I logged into master and altered the same table.  This created an error when the slave tried to replicate, because the column in the table it was altering already existed.  So the replication could not continue.  I ran this command:</p>
<p>&gt;SHOW SLAVE STATUS \G;</p>
<p>This showed me the error, so I went back and deleted the column on the slave so the alter statement on the slave would finish without error.  Then all you have to do is stop slave and then start slave</p>
<p>&gt;STOP SLAVE;</p>
<p>&gt;START SLAVE;</p>
<p>The slave should catch up to the master shortly.  NOTE TO SELF&#8230; make slave user read only.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=138&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2009/11/19/retrying-mysql-slave-query-after-an-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>
	</item>
		<item>
		<title>su on Mac</title>
		<link>http://railsrant.com/2009/11/06/su-on-mac/</link>
		<comments>http://railsrant.com/2009/11/06/su-on-mac/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 14:25:40 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=136</guid>
		<description><![CDATA[I am fairly new to the Mac and I was trying to figure out how to become su when using the Mac terminal. Apparently Mac does not come with su enabled by default.  When I tried the command &#8220;su&#8221;, it prompted me for a password, but I don&#8217;t remember setting a password before.  So in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=136&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I am fairly new to the Mac and I was trying to figure out how to become su when using the Mac terminal. Apparently Mac does not come with su enabled by default.  When I tried the command &#8220;su&#8221;, it prompted me for a password, but I don&#8217;t remember setting a password before.  So in order to get super user access, you have to set the password for root first.  All you need to do is issue this command and you will be able to &#8220;su&#8221;</p>
<p>&gt;sudo passwd root</p>
<p>Enter your user account password and then enter the new root password twice.  After that issue the &#8220;su&#8221; command and enter the password you just created.  You have super user access now.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/136/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=136&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2009/11/06/su-on-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>
	</item>
		<item>
		<title>Using named_scope for object filtering</title>
		<link>http://railsrant.com/2009/10/20/using-named_scope-for-object-filtering/</link>
		<comments>http://railsrant.com/2009/10/20/using-named_scope-for-object-filtering/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 23:46:32 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=126</guid>
		<description><![CDATA[One of the cool new features in Ruby on Rails is the named_scope.  You can put a named_scope in your model as a way to do a customized find by just calling a name.  Here is an example of a simple named_scope.  This named scope gets all the widgets that are blue.  You can call [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=126&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>One of the cool new features in Ruby on Rails is the named_scope.  You can put a named_scope in your model as a way to do a customized find by just calling a name.  Here is an example of a simple named_scope.  This named scope gets all the widgets that are blue.  You can call it like this: <strong>Widget.blues</strong></p>
<div style="border:1px solid #DDD;background-color:#EEE;padding:5px;">
<pre>class Widget &lt; ActiveRecord::Base
  named_scope :blues, :conditions=&gt; "color='blue'"
end
</pre>
</div>
<p>Thats pretty cool huh?  Very DRY if you are going to be using this quite a bit.  Here is a more complex example where you can insert a parameter using lambda.  </p>
<div style="border:1px solid #DDD;background-color:#EEE;padding:5px;">
<pre>
  named_scope :above_price, lambda { |*args| {:conditions =&gt; ["price&gt;?",args.first] } }

  #get all widgets with price above $25
  Widget.above_price(25)
</pre>
</div>
<p>Even cooler&#8230;<br />
Now here is something I like even better that I was not expecting, but it seems to work.  I am able to chain these together to filter out different widgets based on criteria.  This is useful in an application that needs to allow users to filter out certain content based on criteria.  Lets say you have a list full of widgets of all kinds, but the user only wants to see widgets that are blue and cost more than $25.  You can add some check boxes and inputs to your view with a submit button and let the user choose different criteria so they can find the widget they are looking for.  Then you can filter out the widgets with named scopes in your controller</p>
<div style="border:1px solid #DDD;background-color:#EEE;padding:5px;">
<pre>
widgets = Widget.all
if params[:is_blue]
  widgets = widgets.blues
end
if params[:above_price]
  widgets = widgets.above_price(params[:above_price])
end
#now you would have all the blue widgets above whatever price the user entered in the field "above_price"

#If I remember correctly, you can also call them by chaining them together if you need to
widgets = widgets.blue.above_price(25)
</pre>
</div>
<p>I think this is a pretty elegant solution for doing object filtering in Rails.  Go named_scope!  You crazy!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/126/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=126&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2009/10/20/using-named_scope-for-object-filtering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a Facebook (iFrame) app using Ruby on Rails &amp; Facebooker</title>
		<link>http://railsrant.com/2009/10/14/creating-a-facebook-iframe-app-using-ruby-on-rails-facebooker/</link>
		<comments>http://railsrant.com/2009/10/14/creating-a-facebook-iframe-app-using-ruby-on-rails-facebooker/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 18:57:51 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Facebook Apps]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://railsrant.com/?p=96</guid>
		<description><![CDATA[I recently had the pleasure of creating a Facebook app with Ruby on Rails.  At first I thought I might try to write my own code to interact directly with the Facebook API, but after looking at it a bit, I decided I better find some existing software to save me some time.  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=96&subd=johnmcaliley&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I recently had the pleasure of creating a Facebook app with Ruby on Rails.  At first I thought I might try to write my own code to interact directly with the Facebook API, but after looking at it a bit, I decided I better find some existing software to save me some time.  Really the only good choice is <a href="http://github.com/mmangino/facebooker">Facebooker</a>.  rFacebook is also another choice, but it looks like it was abandoned a while ago.  Apparently Facebook has made quite a few changes to the API in the last year or so.  After diving into development I found that Facebooker is not exactly up to date either.  A workaround is pretty easy to code, so I will show you that here.</p>
<p>First thing you want to do when creating a facebook app is to log on to Facebook Developer -&gt; <a href="http://www.facebook.com/developers/">http://www.facebook.com/developers/</a>.  They have 2 sites for this and dont ask me why.  The other one is developer.facebook.com.  Do not use that one, because there is no way to edit your app from that page.</p>
<p>From http://www.facebook.com/developers/, click &#8220;Set up New Application&#8221; and enter an app name.  After that you will go to the &#8220;Edit&#8221; screen for your application.  There are a ton of different things you can configure, like the icon, etc.., but for now you just need to worry about your canvas settings.  Click &#8220;Canvas&#8221; in the left side menu.  Enter a name for your app: http://apps.facebook.com/your-app-name-goes-here .  Next is the most important part, the &#8220;Canvas Callback URL&#8221;.  For this, you need to enter the URL of your application.  Since this is going to be an iFrame application, your app will be retrieved from your servers.  So I entered: http://www.myapp.com/facebook/canvas.  Next make sure you select &#8220;iFrame&#8221; under canvas render method.  Save your changes and its time to start coding with Rails</p>
<p>Here is a screenshot of my settings:<br />
<img class="alignnone size-full wp-image-108" title="Picture 3" src="http://johnmcaliley.files.wordpress.com/2009/10/picture-3.png?w=943&#038;h=642" alt="Picture 3" width="943" height="642" /></p>
<p>You will need to install facebooker as a plugin.  Follow the instructions on github &#8211; <a href="http://github.com/mmangino/facebooker">http://github.com/mmangino/facebooker</a></p>
<p style="width:100%;"><strong>Rails Stuff</strong><br />
1. Create a controller called &#8220;facebook_controller.rb&#8221;<br />
2. Add an action for your canvas page.  This will be like the welcome page for your application<br />
3. Add &#8220;ensure_authenticated_to_facebook&#8221; to the top of your controller.  I will talk about this in more detail later.</p>
<p>4. Set up your view (canvas.html.erb) with whatever you want in it.  &#8220;Hello world&#8221;</p>
<div style="border:1px solid #DDD;background-color:#EEE;padding:5px;">
<pre>class FacebookController &lt; ApplicationController
  ensure_authenticated_to_facebook

  def canvas
  end
end</pre>
</div>
<p>Since you are the developer and you set up the app in facebook, it will already be installed in your facebook account.  You can test it by going to http://apps.facebook.com/name-of-your-app-goes-here<br />
You should see your app render in the iframe.  Now lets move on to where the app actually does something.  Create a link in your view to go to another action that will count your friends</p>
<p><strong>canvas.html.erb</strong></p>
<div style="border:1px solid #DDD;background-color:#EEE;padding:5px;"><code><br />
&lt;%=link_to "count_friends", :action=&gt;"count_friends" %&gt;<br />
</code></div>
<p>Now you need to add the action to your facebook_controller.rb:</p>
<div style="border:1px solid #DDD;background-color:#EEE;padding:5px;">
<pre>def count_friends
  @count = 0
  #this session variable is set automatically by the facebooker plugin
  fbsession = session[:facebook_session]
  #iterate thru your friends.  fbsession.user grabs your user account and then .friends pulls in all your friends
  fbsession.user.friends.each do |user|
    @count += 1
  end
end</pre>
</div>
<p><strong>count_friends.html.erb</strong></p>
<div style="border:1px solid #DDD;background-color:#EEE;padding:5px;">You have  &lt;%=@count%&gt; friends</div>
<p>Woopty doo! You have a working facebook app using Ruby on Rails and Facebooker.</p>
<p>Now if you try to send this to your friends it will not work, because of some changes in the facebook api that were not changed in Facebooker.  The main problem lies in the install_url.  When your friend tries to install the facebook app, it will send them to your website (no iFrame, just your site outside facebook..no good), instead of directing them to your canvas page which contains your website in an iFrame.  To fix this I just hardcoded :canvas=&gt;&#8221;true&#8221; in this method:</p>
<p>starting at line #189 in vendor/plugins/facebooker/lib/facebooker/rails/controller.rb.  I commented out one line and hard coded in a value for canvas.  Not sure if this breaks anything else, but it seems fine so far.  I am guessing facebook changed something with the fb_sig_in_cavas parameter.</p>
<div style="border:1px solid #DDD;background-color:#EEE;padding:5px;">
<pre>      def create_new_facebook_session_and_redirect!
        session[:facebook_session] = new_facebook_session
        next_url = after_facebook_login_url || default_after_facebook_login_url
        #top_redirect_to session[:facebook_session].login_url({:next =&gt; next_url, :canvas=&gt;params[:fb_sig_in_canvas]}) unless @installation_required
        top_redirect_to session[:facebook_session].login_url({:next =&gt; next_url, :canvas=&gt;"true"}) unless @installation_required
        false
      end</pre>
</div>
<p>Push this change to your server and restart your app and this should make everything show up in the iframe after the facebook user installs your app.</p>
<p><strong>On a side note:</strong> if you try to use &#8220;ensure_application_is_installed_by_facebook_user&#8221; in your controller, instead of &#8220;ensure_authenticated_to_facebook&#8221;, you will get the opposite effect when you click on a link within your application.  It will turn into an infinite iframe loop.  Every time you click it will create another page inside the iFrame</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/johnmcaliley.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/johnmcaliley.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/johnmcaliley.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/johnmcaliley.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/johnmcaliley.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/johnmcaliley.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/johnmcaliley.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/johnmcaliley.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/johnmcaliley.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/johnmcaliley.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=railsrant.com&blog=8964095&post=96&subd=johnmcaliley&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://railsrant.com/2009/10/14/creating-a-facebook-iframe-app-using-ruby-on-rails-facebooker/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2fed6c4b838035b8e6b63ca2919c46c6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">John</media:title>
		</media:content>

		<media:content url="http://johnmcaliley.files.wordpress.com/2009/10/picture-3.png" medium="image">
			<media:title type="html">Picture 3</media:title>
		</media:content>
	</item>
	</channel>
</rss>