<?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"
	>

<channel>
	<title>Scott Motte</title>
	<atom:link href="http://scottmotte.com/feed" rel="self" type="application/rss+xml" />
	<link>http://scottmotte.com</link>
	<description>codes a lot</description>
	<pubDate>Wed, 20 Aug 2008 06:26:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Configuring nginx to use www.domain.com instead of domain.com</title>
		<link>http://scottmotte.com/archives/311</link>
		<comments>http://scottmotte.com/archives/311#comments</comments>
		<pubDate>Wed, 20 Aug 2008 06:25:26 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=311</guid>
		<description><![CDATA[I had a client who had their local server setup under domain.com instead of properly under local.domain.com or something similar. It caused a bit of a headache (you could view their new site from outside their local office, but in their local office the old website was still showing.)
Their local server guy (thanks Will) helped [...]]]></description>
			<content:encoded><![CDATA[<p>I had a client who had their local server setup under domain.com instead of properly under local.domain.com or something similar. It caused a bit of a headache (you could view their new site from outside their local office, but in their local office the old website was still showing.)</p>
<p>Their local server guy (thanks Will) helped me solve the issue. Their website needed to use only www.</p>
<p>Here&#8217;s his notes:</p>
<blockquote><p>
Company XYZ Mortuary has two separate DNS systems</p>
<p>1.       The public-facing DNS server that you control</p>
<p>2.       The internal DNS server for Company XYZ’s private network that we control</p>
<p>Since both of these servers are authoritative for the CompanyXYZ.com domain, both need to be updated when IP addresses of public servers change.</p>
<p>The other issue we had was the web site removing the www from the URL, which caused computers on Company XYZ’ private network to access an internal server. Windows domain controllers reserve the IP address for the domain name for themselves, and modifying this behavior breaks functionality such as DFS and Exchange. For this reason, Microsoft and other OS vendors recommend using a TLD that will never be used on the Internet, such as .local.
</p></blockquote>
<p>And here is the adjusted nginx config file to use www &#038; point appropriately.</p>
<p>The key line(s) are:<br />
	server_name company-xyz.com;<br />
     rewrite ^/(.*) http://www.company-xyz.com/$1 permanent;</p>
<pre>
upstream domain4 {
        server 127.0.0.1:3400;
        }

server {
            listen   80;
            server_name company-xyz.com;
            rewrite ^/(.*) http://www.company-xyz.com/$1 permanent;
           }

server {
            listen   80;
            server_name www.company-xyz.com;

            access_log /home/username/public_html/railsapp/shared/log/access.log;
            error_log /home/username/public_html/railsapp/shared/log/error.log;

            root   /home/username/public_html/railsapp/current/public/;
            index  index.html;

            location / {
                          proxy_set_header  X-Real-IP  $remote_addr;
                          proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                          proxy_set_header Host $http_host;
                          proxy_redirect false;

                          if (-f $request_filename/index.html) {
                                           rewrite (.*) $1/index.html break;
                          }

                          if (-f $request_filename.html) {
                                           rewrite (.*) $1.html break;
                          }

                          if (!-f $request_filename) {
                                           proxy_pass http://domain4;
                                           break;
                          }
            }

}

server {

            listen   443;
            ssl on;
            ssl_certificate     /etc/ssl/certs/company-xyz.com.crt;
            ssl_certificate_key   /etc/ssl/private/companyxyz.key;       

            server_name  company-xyz.com;
            rewrite ^/(.*) http://www.company-xyz.com/$1 permanent;

           }

server {

            listen   443;
            ssl on;
            ssl_certificate     /etc/ssl/certs/company-xyz.com.crt;
            ssl_certificate_key   /etc/ssl/private/companyxyz.key;

            server_name www.company-xyz.com;

            access_log /home/username/public_html/railsapp/shared/log/access.log;
            error_log /home/username/public_html/railsapp/shared/log/error.log;

            root   /home/username/public_html/railsapp/current/public/;
            index  index.html;

            location / {
                          proxy_set_header X_FORWARDED_PROTO https;

                          proxy_set_header  X-Real-IP  $remote_addr;
                          proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                          proxy_set_header Host $http_host;
                          proxy_redirect false;

                          if (-f $request_filename/index.html) {
                                           rewrite (.*) $1/index.html break;
                          }

                          if (-f $request_filename.html) {
                                           rewrite (.*) $1.html break;
                          }

                          if (!-f $request_filename) {
                                           proxy_pass http://domain4;
                                           break;
                          }
            }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/311/feed</wfw:commentRss>
		</item>
		<item>
		<title>Scheduled Tasks with Cron in a Rails app</title>
		<link>http://scottmotte.com/archives/307</link>
		<comments>http://scottmotte.com/archives/307#comments</comments>
		<pubDate>Wed, 20 Aug 2008 04:42:42 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=307</guid>
		<description><![CDATA[One of my apps requires a daily task to run. It uses WWW::Mechanize (the gem) to log onto a website, insert a username and password, and save that information, come back to my app, and insert &#038; save that into a form on my site.
I&#8217;m pretty impressed I was able to pull it off. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>One of my apps requires a daily task to run. It uses WWW::Mechanize (the gem) to log onto a website, insert a username and password, and save that information, come back to my app, and insert &#038; save that into a form on my site.</p>
<p>I&#8217;m pretty impressed I was able to pull it off. It&#8217;s a great deal of detail to go into, but I used Recipe 75 in Advanced Rails Recipes and adjusted some of my old <a href="http://scottmotte.com/archives/115">hpricot &#038; mechanize scripts</a>.</p>
<p>Best of all, it keeps me out of the crontab on the server. No hand editing. The capistrano cron rake task takes care of that.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/307/feed</wfw:commentRss>
		</item>
		<item>
		<title>UPDATED: Email validation/activation with rails, restful_authentication, and gmail smtp</title>
		<link>http://scottmotte.com/archives/297</link>
		<comments>http://scottmotte.com/archives/297#comments</comments>
		<pubDate>Tue, 19 Aug 2008 04:39:57 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=297</guid>
		<description><![CDATA[This is updated from my old post on the subject. It&#8217;s a process cheat sheet for me.
I&#8217;m not gonna explain it too much. Here&#8217;s the code.

script/plugin install git://github.com/technoweenie/restful-authentication.git


script/generate authenticated user sessions --include-activation


1
2
3
#Add an observer to config/environment.rb
config.active_record.observers = :user_observer
#put it just before the very last 'end' on the page


1
2
3
4
5
#Add routes to these resources. In config/routes.rb, insert [...]]]></description>
			<content:encoded><![CDATA[<p>This is updated from my <a href="http://scottmotte.com/archives/21">old post on the subject</a>. It&#8217;s a process cheat sheet for me.</p>
<p>I&#8217;m not gonna explain it too much. Here&#8217;s the code.</p>

<div class="wp_syntax"><div class="code"><pre class="bash">script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>technoweenie<span style="color: #000000; font-weight: bold;">/</span>restful-authentication.git</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash">script<span style="color: #000000; font-weight: bold;">/</span>generate authenticated user sessions --include-activation</pre></div></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#Add an observer to config/environment.rb</span>
config.<span style="color:#9900CC;">active_record</span>.<span style="color:#9900CC;">observers</span> = <span style="color:#ff3333; font-weight:bold;">:user_observer</span>
<span style="color:#008000; font-style:italic;">#put it just before the very last 'end' on the page</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#Add routes to these resources. In config/routes.rb, insert routes like:</span>
    map.<span style="color:#9900CC;">signup</span> <span style="color:#996600;">'/signup'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'users'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'new'</span>
    map.<span style="color:#9900CC;">login</span>  <span style="color:#996600;">'/login'</span>,  <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'sessions'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'new'</span>
    map.<span style="color:#9900CC;">logout</span> <span style="color:#996600;">'/logout'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'sessions'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'destroy'</span>
    map.<span style="color:#9900CC;">activate</span> <span style="color:#996600;">'/activate/:activation_code'</span>, <span style="color:#ff3333; font-weight:bold;">:controller</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'users'</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'activate'</span>, <span style="color:#ff3333; font-weight:bold;">:activation_code</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span></pre></td></tr></table></div>


<div class="wp_syntax"><div class="code"><pre class="bash">rake db:migrate</pre></div></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># create new file config/initializers/mail.rb</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;smtp_tls&quot;</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>.<span style="color:#9900CC;">delivery_method</span> = <span style="color:#ff3333; font-weight:bold;">:smtp</span>
<span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>.<span style="color:#9900CC;">smtp_settings</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
<span style="color:#ff3333; font-weight:bold;">:address</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;smtp.gmail.com&quot;</span>,
<span style="color:#ff3333; font-weight:bold;">:port</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">587</span>,
<span style="color:#ff3333; font-weight:bold;">:authentication</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:plain</span>,
<span style="color:#ff3333; font-weight:bold;">:user_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;you@gmail.com&quot;</span>,
<span style="color:#ff3333; font-weight:bold;">:password</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'yourpassword'</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># edit config/environments/production.rb &amp; put these lines at the top</span>
SITE_NAME = <span style="color:#996600;">&quot;Your Site&quot;</span>
SITE_URL = <span style="color:#996600;">&quot;www.yourdomain.com&quot;</span>
SITE_EMAIL = <span style="color:#996600;">&quot;admin@yourdomain.com&quot;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># edit config/environments/development.rb &amp; put these lines at the top</span>
SITE_NAME = <span style="color:#996600;">&quot;ToolTime&quot;</span>
SITE_URL = <span style="color:#996600;">&quot;localhost:3000&quot;</span>
SITE_EMAIL = <span style="color:#996600;">&quot;scott@scottmotte.com&quot;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># Make app/models/user_mailer.rb look like the following:</span>
<span style="color:#9966CC; font-weight:bold;">class</span> UserMailer <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> signup_notification<span style="color:#006600; font-weight:bold;">&#40;</span>user<span style="color:#006600; font-weight:bold;">&#41;</span>
    setup_email<span style="color:#006600; font-weight:bold;">&#40;</span>user<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@subject</span>    <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#996600;">'Please activate your new account'</span>
&nbsp;
    <span style="color:#0066ff; font-weight:bold;">@body</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:url</span><span style="color:#006600; font-weight:bold;">&#93;</span>  = <span style="color:#996600;">&quot;http://#{SITE_URL}/activate/#{user.activation_code}&quot;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> activation<span style="color:#006600; font-weight:bold;">&#40;</span>user<span style="color:#006600; font-weight:bold;">&#41;</span>
    setup_email<span style="color:#006600; font-weight:bold;">&#40;</span>user<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@subject</span>    <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#996600;">'Your account has been activated!'</span>
    <span style="color:#0066ff; font-weight:bold;">@body</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:url</span><span style="color:#006600; font-weight:bold;">&#93;</span>  = <span style="color:#996600;">&quot;http://#{SITE_URL}/&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  protected
    <span style="color:#9966CC; font-weight:bold;">def</span> setup_email<span style="color:#006600; font-weight:bold;">&#40;</span>user<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@recipients</span>  = <span style="color:#996600;">&quot;#{user.email}&quot;</span>
      <span style="color:#0066ff; font-weight:bold;">@from</span>        = <span style="color:#996600;">&quot;#{SITE_EMAIL}&quot;</span>
      <span style="color:#0066ff; font-weight:bold;">@subject</span>     = <span style="color:#996600;">&quot;#{SITE_NAME}&quot;</span>
      <span style="color:#0066ff; font-weight:bold;">@sent_on</span>     = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
      <span style="color:#0066ff; font-weight:bold;">@body</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user</span><span style="color:#006600; font-weight:bold;">&#93;</span> = user
    <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># create file lib/smtp_tls.rb with following code in it</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;openssl&quot;</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;net/smtp&quot;</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">Net::SMTP</span>.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  private
  <span style="color:#9966CC; font-weight:bold;">def</span> do_start<span style="color:#006600; font-weight:bold;">&#40;</span>helodomain, user, secret, authtype<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">IOError</span>, <span style="color:#996600;">'SMTP session already started'</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@started</span>
    check_auth_args user, secret, authtype <span style="color:#9966CC; font-weight:bold;">if</span> user <span style="color:#9966CC; font-weight:bold;">or</span> secret
&nbsp;
    sock = timeout<span style="color:#006600; font-weight:bold;">&#40;</span>@open_timeout<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> TCPSocket.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>@address, <span style="color:#0066ff; font-weight:bold;">@port</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#0066ff; font-weight:bold;">@socket</span> = <span style="color:#6666ff; font-weight:bold;">Net::InternetMessageIO</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>sock<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">read_timeout</span> = <span style="color:#006666;">60</span> <span style="color:#008000; font-style:italic;">#@read_timeout</span>
&nbsp;
    check_response<span style="color:#006600; font-weight:bold;">&#40;</span>critical <span style="color:#006600; font-weight:bold;">&#123;</span> recv_response<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    do_helo<span style="color:#006600; font-weight:bold;">&#40;</span>helodomain<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">if</span> starttls
      <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">'openssl library not installed'</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#9966CC; font-weight:bold;">defined</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>OpenSSL<span style="color:#006600; font-weight:bold;">&#41;</span>
      ssl = <span style="color:#6666ff; font-weight:bold;">OpenSSL::SSL::SSLSocket</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>sock<span style="color:#006600; font-weight:bold;">&#41;</span>
      ssl.<span style="color:#9900CC;">sync_close</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
      ssl.<span style="color:#9900CC;">connect</span>
      <span style="color:#0066ff; font-weight:bold;">@socket</span> = <span style="color:#6666ff; font-weight:bold;">Net::InternetMessageIO</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>ssl<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">read_timeout</span> = <span style="color:#006666;">60</span> <span style="color:#008000; font-style:italic;">#@read_timeout</span>
      do_helo<span style="color:#006600; font-weight:bold;">&#40;</span>helodomain<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    authenticate user, secret, authtype <span style="color:#9966CC; font-weight:bold;">if</span> user
    <span style="color:#0066ff; font-weight:bold;">@started</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#9966CC; font-weight:bold;">ensure</span>
    <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@started</span>
      <span style="color:#008000; font-style:italic;"># authentication failed, cancel connection.</span>
      <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">close</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">not</span> <span style="color:#0066ff; font-weight:bold;">@started</span> <span style="color:#9966CC; font-weight:bold;">and</span> <span style="color:#0066ff; font-weight:bold;">@socket</span> <span style="color:#9966CC; font-weight:bold;">and</span> <span style="color:#9966CC; font-weight:bold;">not</span> <span style="color:#0066ff; font-weight:bold;">@socket</span>.<span style="color:#9900CC;">closed</span>?
      <span style="color:#0066ff; font-weight:bold;">@socket</span> = <span style="color:#0000FF; font-weight:bold;">nil</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> do_helo<span style="color:#006600; font-weight:bold;">&#40;</span>helodomain<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@esmtp</span>
        ehlo helodomain
      <span style="color:#9966CC; font-weight:bold;">else</span>
        helo helodomain
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">Net::ProtocolError</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@esmtp</span>
        <span style="color:#0066ff; font-weight:bold;">@esmtp</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
        <span style="color:#0066ff; font-weight:bold;">@error_occured</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
        <span style="color:#9966CC; font-weight:bold;">retry</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#CC0066; font-weight:bold;">raise</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> starttls
    getok<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'STARTTLS'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>
  <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> quit
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      getok<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'QUIT'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">EOFError</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Restart your server, visit http://yourapp.com/signup and give it a shot.</p>
<p>Once that works. Then put before_filter :login_required in your controllers where needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/297/feed</wfw:commentRss>
		</item>
		<item>
		<title>Autotest</title>
		<link>http://scottmotte.com/archives/292</link>
		<comments>http://scottmotte.com/archives/292#comments</comments>
		<pubDate>Mon, 18 Aug 2008 21:26:44 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=292</guid>
		<description><![CDATA[Getting started tutorial
]]></description>
			<content:encoded><![CDATA[<p><a href="http://ph7spot.com/articles/getting_started_with_autotest">Getting started tutorial</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/292/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to check for all your rake tasks</title>
		<link>http://scottmotte.com/archives/290</link>
		<comments>http://scottmotte.com/archives/290#comments</comments>
		<pubDate>Mon, 18 Aug 2008 18:54:55 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=290</guid>
		<description><![CDATA[In terminal

rake -T

]]></description>
			<content:encoded><![CDATA[<p>In terminal</p>

<div class="wp_syntax"><div class="code"><pre class="bash">rake -T</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/290/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to open files in terminal</title>
		<link>http://scottmotte.com/archives/286</link>
		<comments>http://scottmotte.com/archives/286#comments</comments>
		<pubDate>Mon, 18 Aug 2008 18:47:42 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=286</guid>
		<description><![CDATA[
open -a Firefox doc/plugins/rspec-rails/index.html

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash">open -a Firefox doc<span style="color: #000000; font-weight: bold;">/</span>plugins<span style="color: #000000; font-weight: bold;">/</span>rspec-rails<span style="color: #000000; font-weight: bold;">/</span>index.html</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/286/feed</wfw:commentRss>
		</item>
		<item>
		<title>My Terminal bash settings</title>
		<link>http://scottmotte.com/archives/282</link>
		<comments>http://scottmotte.com/archives/282#comments</comments>
		<pubDate>Mon, 18 Aug 2008 18:40:24 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=282</guid>
		<description><![CDATA[
cd ~
mate .bashrc # or nano .bashrc


1
2
# then type in
export PS1='\[[~/\W]'

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #7a0874; font-weight: bold;">cd</span> ~
mate .bashrc <span style="color: #666666; font-style: italic;"># or nano .bashrc</span></pre></div></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># then type in</span>
export PS1=<span style="color:#996600;">'<span style="color:#000099;">\[</span>[~/<span style="color:#000099;">\W</span>]'</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/282/feed</wfw:commentRss>
		</item>
		<item>
		<title>WP-Syntax</title>
		<link>http://scottmotte.com/archives/263</link>
		<comments>http://scottmotte.com/archives/263#comments</comments>
		<pubDate>Sun, 17 Aug 2008 18:06:58 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=263</guid>
		<description><![CDATA[I&#8217;ve installed WP-Syntax on my blog. It will help brighten up my lines of code.
It was an easy install and pretty easy to use. Intead, of just using the pre html tag, I know do something like this:
pre lang=&#8221;ruby&#8221; line=&#8221;1&#8243;
#put some ruby code
Categories.find(:all, :conditions => ['cool_field = ?', 'awesome'])
pre

1
2
#put some ruby code
Categories.find&#40;:all, :conditions =&#62; &#91;'cool_field [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve installed <a href="http://wordpress.org/extend/plugins/wp-syntax/">WP-Syntax</a> on my blog. It will help brighten up my lines of code.</p>
<p>It was an easy install and pretty easy to use. Intead, of just using the pre html tag, I know do something like this:</p>
<p>pre lang=&#8221;ruby&#8221; line=&#8221;1&#8243;<br />
#put some ruby code<br />
Categories.find(:all, :conditions => ['cool_field = ?', 'awesome'])<br />
pre</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;">#put some ruby code</span>
Categories.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'cool_field = ?'</span>, <span style="color:#996600;">'awesome'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>or html</p>
<p>pre lang=&#8221;html4strict&#8221; line=&#8221;1&#8243;><br />
<!-- comment --></p>
<h1>Title me</h1>
<p>That car was bright blue.</p>
<p>pre</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html4strict"><span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- comment --&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1&gt;</span></span>Title me<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></span>That car was bright blue.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/263/feed</wfw:commentRss>
		</item>
		<item>
		<title>Slicehost, nginx, mysql, php, wordpress setup</title>
		<link>http://scottmotte.com/archives/253</link>
		<comments>http://scottmotte.com/archives/253#comments</comments>
		<pubDate>Sun, 17 Aug 2008 17:52:41 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=253</guid>
		<description><![CDATA[Detailed tutorial on nginx, mysql, php, wordpress setup. bonus: it includes setup instructions for the super cache plugin
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mensk.com/webmaster-toolbox/perfect-ubuntu-hardy-nginx-mysql5-php5-wordpress/">Detailed tutorial on nginx, mysql, php, wordpress setup.</a> bonus: it includes setup instructions for the super cache plugin</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/253/feed</wfw:commentRss>
		</item>
		<item>
		<title>Rails model validation without database using active_form</title>
		<link>http://scottmotte.com/archives/274</link>
		<comments>http://scottmotte.com/archives/274#comments</comments>
		<pubDate>Sun, 17 Aug 2008 23:28:01 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=274</guid>
		<description><![CDATA[Usually, when you create a model, you create a database, and then the model works with ActiveRecord. And it&#8217;s ActiveRecord (as far as I currently know) that lets you use validation techniques. 
So how do we add validation techniques to something like a contact form on our Rails site that does not have a database?
Install [...]]]></description>
			<content:encoded><![CDATA[<p>Usually, when you create a model, you create a database, and then the model works with ActiveRecord. And it&#8217;s ActiveRecord (as far as I currently know) that lets you use validation techniques. </p>
<p>So how do we add validation techniques to something like a contact form on our Rails site that does not have a database?</p>
<p>Install the plugin active form</p>

<div class="wp_syntax"><div class="code"><pre class="bash">script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>xgamerx<span style="color: #000000; font-weight: bold;">/</span>active_form.git</pre></div></div>

<p>Then create a file in your app/models folder called email.rb. Paste in the following into that file. Line #1 is key</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Email <span style="color:#006600; font-weight:bold;">&lt;</span> ActiveForm
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:email_address</span>, <span style="color:#ff3333; font-weight:bold;">:message</span>
  validates_presence_of <span style="color:#ff3333; font-weight:bold;">:message</span>
  validates_presence_of <span style="color:#ff3333; font-weight:bold;">:email_address</span>
  validates_presence_of <span style="color:#ff3333; font-weight:bold;">:name</span> 
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Then create another file in app/models called contact_emailer.rb and paste in the following. This is what will let you send the email </p>
<p><small>(Wait: make sure you know how to setup email so it works. See my post on <a href="http://scottmotte.com/archives/159">creating a contact form with gmail smtp and rails</a>. In that post I called the following file Emailer.rb. You could do that as well, but Line #1 with ActionMailer::Base is key.)</small></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> ContactMailer <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> contact_email<span style="color:#006600; font-weight:bold;">&#40;</span>email<span style="color:#006600; font-weight:bold;">&#41;</span>
      recipients  <span style="color:#996600;">&quot;site@email.com&quot;</span> 
      headers     <span style="color:#996600;">&quot;Reply-to&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{email.email_address}&quot;</span>
      from        email.<span style="color:#9900CC;">name</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot; &lt;&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> email.<span style="color:#9900CC;">email_address</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;&gt;&quot;</span>
      subject     <span style="color:#996600;">&quot;SiteName&quot;</span>
      body        <span style="color:#ff3333; font-weight:bold;">:email</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> email
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Then in your views create a folder called contact_mailer &#038; inside of that folder create a file called contact_email.html.erb<br />
app<br />
-views<br />
&#8211;contact_mailer<br />
&#8212;contact_email.html.erb</p>
<p>This will style the email so put something like the following. This essentially routes to the contact_email method in contact_mailer.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="ruby">Name:
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#0066ff; font-weight:bold;">@email</span>.<span style="color:#9900CC;">name</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
Email: 
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#0066ff; font-weight:bold;">@email</span>.<span style="color:#9900CC;">email_address</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
&nbsp;
Message:
&nbsp;
<span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#0066ff; font-weight:bold;">@email</span>.<span style="color:#9900CC;">message</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>Now you can create a controller and use the form. Here&#8217;s an example using a static based site. The key is line #14 (ContactMailer.deliver_contact_email(@email)). This uses the contact_email method we created, and rails knows that if you put deliver_ in front of it, then it will deliver it according to your email setup (which you shoud have done already <a href="http://scottmotte.com/archives/159">here</a>).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># static controler</span>
<span style="color:#9966CC; font-weight:bold;">class</span> StaticController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> index
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> overview
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> faqs    
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> contact
    <span style="color:#9966CC; font-weight:bold;">if</span> request.<span style="color:#9900CC;">post</span>?
      <span style="color:#0066ff; font-weight:bold;">@email</span> = Email.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@email</span>.<span style="color:#9900CC;">valid</span>?
        ContactMailer.<span style="color:#9900CC;">deliver_contact_email</span><span style="color:#006600; font-weight:bold;">&#40;</span>@email<span style="color:#006600; font-weight:bold;">&#41;</span>
        flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Your email was sent successfully. Thanks.&quot;</span>
        <span style="color:#008000; font-style:italic;"># without the redirect the params[:email] gets filled back into the form making it look like the form did not get submitted</span>
        redirect_to <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'contact'</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> signup    
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>And here&#8217;s what the contact.html.erb looks like associated with that action.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="html4strict">&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1&gt;</span></span>Contact Us<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></span>Email us.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span>
&nbsp;
<span style="color: #009900;">&lt;% form_tag<span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#123;</span>:<span style="color: #000066;">action</span> <span style="color: #66cc66;">=</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> &quot;contact&quot;}, :id =&gt; 'contact') do %&gt;
<span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> error_messages_for<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'email'</span><span style="color: #66cc66;">&#41;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ul&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email_name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Your Name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label&gt;</span></span>
		<span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> text_field <span style="color: #ff0000;">&quot;email&quot;</span>, <span style="color: #ff0000;">&quot;name&quot;</span>, :<span style="color: #000066;">class</span> <span style="color: #66cc66;">=</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 'input-txt' %&gt;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email_company&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Your Email Address<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label&gt;</span></span>
		<span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> text_field <span style="color: #ff0000;">&quot;email&quot;</span>, <span style="color: #ff0000;">&quot;email_address&quot;</span>, :<span style="color: #000066;">class</span> <span style="color: #66cc66;">=</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 'input-txt' %&gt;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email_message&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Message<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label&gt;</span></span>
		<span style="color: #009900;">&lt;%<span style="color: #66cc66;">=</span> text_area <span style="color: #ff0000;">&quot;email&quot;</span>, <span style="color: #ff0000;">&quot;message&quot;</span>, :<span style="color: #000066;">cols</span> <span style="color: #66cc66;">=</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 10 %&gt;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;actn&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- &lt;a id=&quot;sendmessage&quot; href=&quot;&quot;&gt;</span></span>Send Message<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span> --&gt;
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Send Message&quot;</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span>
<span style="color: #009900;">&lt;% end %<span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></td></tr></table></div>

<p>Finally, make sure to restart your local server using script/server before testing. Otherwise, the plugin active_form won&#8217;t load the first time. </p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/274/feed</wfw:commentRss>
		</item>
		<item>
		<title>Pluralization in Rails</title>
		<link>http://scottmotte.com/archives/251</link>
		<comments>http://scottmotte.com/archives/251#comments</comments>
		<pubDate>Sun, 17 Aug 2008 11:37:40 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=251</guid>
		<description><![CDATA[
Recent &#60;%= category.title.pluralize %&#62;
# Recent posts
# Recent blogs

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby">Recent <span style="color:#006600; font-weight:bold;">&lt;%</span>= category.<span style="color:#9900CC;">title</span>.<span style="color:#9900CC;">pluralize</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#008000; font-style:italic;"># Recent posts</span>
<span style="color:#008000; font-style:italic;"># Recent blogs</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/251/feed</wfw:commentRss>
		</item>
		<item>
		<title>Handling validations across associations in Rails</title>
		<link>http://scottmotte.com/archives/245</link>
		<comments>http://scottmotte.com/archives/245#comments</comments>
		<pubDate>Sat, 16 Aug 2008 23:42:13 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=245</guid>
		<description><![CDATA[That&#8217;s kind of fun to say out loud.
Here&#8217;s a recent solution from Ryan Bates for handling validations across associations in Rails.
The key code is:

  validate :category_must_exist
&#160;
  def category_must_exist
    errors.add&#40;:category_id, &#34;can't be blank&#34;&#41; if category_id.blank?
  end

If you are new to how these custom validations work, here&#8217;s some more context.

class Post [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s kind of fun to say out loud.</p>
<p>Here&#8217;s a recent <a href="http://forums.pragprog.com/forums/74/topics/732">solution from Ryan Bates for handling validations across associations in Rails</a>.</p>
<p>The key code is:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">  validate <span style="color:#ff3333; font-weight:bold;">:category_must_exist</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> category_must_exist
    errors.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:category_id</span>, <span style="color:#996600;">&quot;can't be blank&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> category_id.<span style="color:#9900CC;">blank</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>If you are new to how these custom validations work, here&#8217;s some more context.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Post <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:category</span>
&nbsp;
  validates_presence_of <span style="color:#ff3333; font-weight:bold;">:title</span>
  validates_presence_of <span style="color:#ff3333; font-weight:bold;">:permalink</span>
  validates_uniqueness_of <span style="color:#ff3333; font-weight:bold;">:permalink</span> 
  validate <span style="color:#ff3333; font-weight:bold;">:category_must_exist</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> category_must_exist
    errors.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:category_id</span>, <span style="color:#996600;">&quot;can't be blank&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> category_id.<span style="color:#9900CC;">blank</span>?
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>and my category model looks like this (so each post only has one category as of now.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Category <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:posts</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/245/feed</wfw:commentRss>
		</item>
		<item>
		<title>Remove and Add columns to the database the Rails 2.0 way</title>
		<link>http://scottmotte.com/archives/241</link>
		<comments>http://scottmotte.com/archives/241#comments</comments>
		<pubDate>Sat, 16 Aug 2008 22:06:12 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=241</guid>
		<description><![CDATA[Use change_table and its sub methods rather than remove_column and add_column
Resource

#example
class AddCategoryIdToPosts < ActiveRecord::Migration
  def self.up
    change_table :posts do &#124;t&#124;
      t.references :category
    end
  end

  def self.down
    change_table :posts do &#124;t&#124;
      t.remove_references :category
  [...]]]></description>
			<content:encoded><![CDATA[<p>Use change_table and its sub methods rather than remove_column and add_column</p>
<p><a href="http://rails.lighthouseapp.com/projects/8994/tickets/71-add-change_table-to-core">Resource</a></p>
<pre>
#example
class AddCategoryIdToPosts < ActiveRecord::Migration
  def self.up
    change_table :posts do |t|
      t.references :category
    end
  end

  def self.down
    change_table :posts do |t|
      t.remove_references :category
    end
  end
end
</pre>
<pre>
# another exmample. note remove_integer doesn't work. just use plain old 'remove'
class AddRedirectLocaleToPages < ActiveRecord::Migration
  def self.up
    change_table :pages do |t|
      t.integer :redirect_locale, :default => 0
    end
  end

  def self.down
    change_table :pages do |t|
      t.remove :redirect_locale, :default => 0
    end
  end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/241/feed</wfw:commentRss>
		</item>
		<item>
		<title>Dynamically hiding/toggling a textfield with a drop down select box using rails and javascript</title>
		<link>http://scottmotte.com/archives/239</link>
		<comments>http://scottmotte.com/archives/239#comments</comments>
		<pubDate>Sat, 16 Aug 2008 18:10:33 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=239</guid>
		<description><![CDATA[This comes from this post on railsforum.
First, make sure you can do the basic javascript. See the pastie.
As you can see we are just going to use a basic toggle. Let&#8217;s keep things simple to start.
Now make sure you&#8217;re capable of doing a basic select box with selected working.

	
	 1,
		"No. (keep as a normal page)" [...]]]></description>
			<content:encoded><![CDATA[<p>This comes from <a href="http://railsforum.com/viewtopic.php?id=5397">this post on railsforum</a>.</p>
<p>First, make sure you can do the basic javascript. <a href="http://pastie.org/254193">See the pastie</a>.</p>
<p>As you can see we are just going to use a basic toggle. Let&#8217;s keep things simple to start.</p>
<p>Now make sure you&#8217;re capable of doing a basic select box with selected working.</p>
<pre>
	<%= f.label :redirect_locale, 'Page redirect:' %>
	<%= select("page", "redirect_locale", {
		"Yes, to posts. (works like a blog or news)" => 1,
		"No. (keep as a normal page)" => 0,
	  }, { :selected => @page.redirect_locale })%>
</pre>
<p>Now combine what you just did, but let&#8217;s use show and hide instead of toggle</p>
<pre>
<%= f.label :redirect_locale, 'Page redirect:' %>
	<%= select("page", "redirect_locale",
		{"Yes, to posts. (works like a blog or news)" => 1, "No. (keep as a normal page)" => 0,},
		{ :selected => @page.redirect_locale },
		{ :onchange => "if (this.value == '1') { $('body_toggle').hide(); $('sidebar_toggle').hide() } else { $('body_toggle').show(); $('sidebar_toggle').show(); }" })%>
</pre>
<p>That should work as long as you have some divs or spans or p with the id=&#8221;sidebar_toggle&#8221; and id=&#8221;body_toggle&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/239/feed</wfw:commentRss>
		</item>
		<item>
		<title>Using Capistrano and git to deploy from a local location</title>
		<link>http://scottmotte.com/archives/233</link>
		<comments>http://scottmotte.com/archives/233#comments</comments>
		<pubDate>Fri, 15 Aug 2008 21:51:49 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=233</guid>
		<description><![CDATA[Here&#8217;s the inspirational link. Basically, you use capistrano to deploy_via, :copy rather than :remote_cache. And you don&#8217;t have to worry about setting up gitosis or paying for github. However, I would not recommend this if you are working with another team member on the code. This is good for things you simply keep and work [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wiki.brightbox.co.uk/docs:gemv2:repositories">Here&#8217;s the inspirational link.</a> Basically, you use capistrano to deploy_via, :copy rather than :remote_cache. And you don&#8217;t have to worry about setting up gitosis or paying for github. However, I would not recommend this if you are working with another team member on the code. This is good for things you simply keep and work on locally. For example, I am keeping a client cms this way.</p>
<p>This is best used with passenger (mod_rails).</p>
<p>Here&#8217;s the capistrano deploy file:</p>
<pre>
set :runner, "scottmotte"
set :use_sudo, false

# =============================================================================
# CUSTOM OPTIONS
# =============================================================================
set :user, "scottmotte"
set :application, "motte_cms"
set :domain, "209.20.84.209"
set :site_url, "uniteddev.com"

role :web, domain
role :app, domain
role :db,  domain, :primary => true

# =============================================================================
# DATABASE OPTIONS
# =============================================================================
 set :rails_env,       "production"

# =============================================================================
# DEPLOY TO
# =============================================================================
set :deploy_to, "/home/#{user}/public_html/#{site_url}"

# =============================================================================
# REPOSITORY
# =============================================================================
set :scm, "git"
set :repository,  %w(/Users/scottmotte/Documents/code/rails/motte_cms)
set :branch, "uniteddev"
set :deploy_via, :copy
set :copy_exclude, [".svn", ".git"]

# =============================================================================
# SSH OPTIONS
# =============================================================================

default_run_options[:pty] = true
ssh_options[:paranoid] = false
ssh_options[:keys] = %w(/Users/scottmotte/.ssh/id_rsa)
ssh_options[:port] = 2008
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/233/feed</wfw:commentRss>
		</item>
		<item>
		<title>Managing Linux Users</title>
		<link>http://scottmotte.com/archives/227</link>
		<comments>http://scottmotte.com/archives/227#comments</comments>
		<pubDate>Fri, 15 Aug 2008 20:00:58 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=227</guid>
		<description><![CDATA[Handy cheat sheet for managing linux users
]]></description>
			<content:encoded><![CDATA[<p>Handy cheat sheet for <a href="http://www.comptechdoc.org/os/linux/usersguide/linux_ugusers.html">managing linux users</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/227/feed</wfw:commentRss>
		</item>
		<item>
		<title>Installing git on your slicehost and managing it with gitosis</title>
		<link>http://scottmotte.com/archives/209</link>
		<comments>http://scottmotte.com/archives/209#comments</comments>
		<pubDate>Fri, 15 Aug 2008 07:03:27 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=209</guid>
		<description><![CDATA[FINAL UPDATE: The following is a mind dump. It might be useful, but it is not longer the exact path I took.
Instead I followed the scientist article, but when it came to creating the git user I followed the slicehost article for ubuntu (which I am on).
&#8212;
Most all of this comes from the excellent article [...]]]></description>
			<content:encoded><![CDATA[<p>FINAL UPDATE: The following is a mind dump. It might be useful, but it is not longer the exact path I took.</p>
<p>Instead I followed the <a href="http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way/comments/2206#comment-2206">scientist article</a>, but when it came to creating the git user I followed the <a href="http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-1">slicehost article for ubuntu</a> (which I am on).</p>
<p>&#8212;<br />
Most all of this comes from the excellent <a href="http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way/comments/2206#comment-2206">article by scientist on hosting git repositories the easy and secure way</a> with some adjustments for my own setup that you might find useful to get you started, especially if you&#8217;re a newb at this like me.</p>
<p>If you hosting your private projects on github is becoming to expensive you can do the following and host your projects with git on slicehost (or any vps for that matter) using gitosis.</p>
<p><strong>First, let&#8217;s install git on our server.<br />
</strong><br />
I recommend installing from source. Some people ran into problems using apt-get (<a href="http://forum.slicehost.com/comments.php?DiscussionID=1379#Item_6">source</a>)</p>
<p># 1.5.6 as of Aug 14th, 2008</p>
<pre>
sudo apt-get remove git git-svn
mkdir ~/sources
cd ~/sources
wget http://kernel.org/pub/software/scm/git/git-1.5.6.tar.bz2
sudo apt-get build-dep git-core
tar xjf git-1.5.6.tar.bz2
cd git-1.5.6/
./configure
make
sudo make install
</pre>
<p>Test that git is installed.</p>
<pre>
git --version
# git version 1.5.6
</pre>
<p>Good. Now you can delete all the contents of the ~/sources directory if you&#8217;d like.</p>
<p><strong>Second, let&#8217;s install gitosis.</strong> (<a href="http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way">source</a>)</p>
<pre>
cd ~/src
git clone git://eagain.net/gitosis.git
sudo apt-get install python-setuptools
cd gitosis
sudo python setup.py install #this hung me up for a while. I thought gitosis was installed, but it wasn't. I had to run sudo.
</pre>
<p>UPDATE: I just used my standard user already setup on slicehost.<br />
<strike><br />
After that installs setup your user. It could be different than &#8216;git&#8217;, but let&#8217;s just use &#8216;git&#8217; as the user.</p>
<pre>
sudo adduser \
    --system \
    --shell /bin/sh \
    --gecos 'git version control' \
    --group \
    --disabled-password \
    --home /home/git \
    git
</pre>
<p></strike></p>
<p>Now copy your ~/.ssh/id_rsa.pub on your LOCAL COMPUTER to your server.</p>
<pre>
# on your LOCAL computer
cd ~/.ssh
cat id_rsa.pub
#copy and paste what spits out
</pre>
<pre>
# on your slicehost server
cd /tmp
sudo nano id_rsa.pub
# paste in what you copied from your local computer
</pre>
<p>Now let&#8217;s put your public SSH key into gitosis&#8217; permission</p>
<pre>
cd ~
sudo -H -u scottmotte gitosis-init < /tmp/id_rsa.pub
<strike>sudo -H -u git gitosis-init < /tmp/id_rsa.pub</strike>
</pre>
<p>Next</p>
<pre>
sudo chmod 755 /home/scottmotte/repositories/gitosis-admin.git/hooks/post-update
<strike>sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update</strike>
</pre>
<p>Then back on your local machine account for the fact that I run ssh on a different port (put your port here)</p>
<pre>
sudo nano ~/.ssh/config
</pre>
<p>put this inside<br />
Host www.example.com<br />
    Port 32767</p>
<p><strike>UPDATE: The above didn&#8217;t work for me like the <a href="http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way">scientist post on hosting git repositories the easy and secure way</a> said so I took a look at the <a href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html">git clone documentation</a> and realized I could put ssh:// in front of the git clone string. Then I was able to add the port at the end of the string without it crapping out.</strike><br />
It didn&#8217;t work because I&#8217;m retarded and was doing sudo nano ~/.ssh/config on my server rather than locally. Make sure you do this locally.</p>
<pre>
cd ~/documents/code
git clone scottmotte@209.1.1.xxx:gitosis-admin.git
or
git clone ssh://scottmotte@209.1.1.xxx:32767/home/scottmotte/repositories/gitosis-admin.git
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/209/feed</wfw:commentRss>
		</item>
		<item>
		<title>Test if a string is an integer with Ruby</title>
		<link>http://scottmotte.com/archives/207</link>
		<comments>http://scottmotte.com/archives/207#comments</comments>
		<pubDate>Fri, 15 Aug 2008 03:45:25 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=207</guid>
		<description><![CDATA[
	
		Nice
	
		$#%@
	

in irb

12.is_a?(Integer)
=> true

from Introduction to Ruby
]]></description>
			<content:encoded><![CDATA[<pre>
	<% if params[:page].is_a?(Integer) %>
		Nice
	<% else %>
		$#%@
	<% end %>
</pre>
<p>in irb</p>
<pre>
12.is_a?(Integer)
=> true
</pre>
<p><a href="http://www.ruby-doc.org/docs/Tutorial/part_01/objects.html">from Introduction to Ruby</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/207/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to setup wysiwyg editing for rails - yui_editor</title>
		<link>http://scottmotte.com/archives/196</link>
		<comments>http://scottmotte.com/archives/196#comments</comments>
		<pubDate>Fri, 15 Aug 2008 00:19:27 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=196</guid>
		<description><![CDATA[Previously, I was using tinymce on my rails app along with the plugin. I&#8217;ve since moved to using the yui_editor through larslevan&#8217;s plugin on github.
I am currently much happier with the yui_editor and would recommend it over anything else I&#8217;ve been able to find out there.
Plus, setup was a breeze. Thanks larsklevan.
Here&#8217;s the api documentation [...]]]></description>
			<content:encoded><![CDATA[<p>Previously, I was using <a href="http://scottmotte.com/archives/65">tinymce on my rails app</a> along with the plugin. I&#8217;ve since moved to using the <a href="http://github.com/larsklevan/yui_editor/tree/master">yui_editor through larslevan&#8217;s plugin on github</a>.</p>
<p>I am currently much happier with the yui_editor and would recommend it over anything else I&#8217;ve been able to find out there.</p>
<p>Plus, setup was a breeze. Thanks larsklevan.</p>
<p>Here&#8217;s the <a href="http://developer.yahoo.com/yui/docs/">api documentation for the yui editor</a>.</p>
<p><a href="http://developer.yahoo.com/yui/examples/editor/skinning_editor.html">How to skin the yui editor with css</a>.</p>
<p>And here&#8217;s <a href="http://developer.yahoo.com/yui/examples/editor/imagebrowser_editor.html">how to setup a custom image browser</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/196/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to put a partial form in form_for</title>
		<link>http://scottmotte.com/archives/193</link>
		<comments>http://scottmotte.com/archives/193#comments</comments>
		<pubDate>Thu, 14 Aug 2008 23:44:16 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=193</guid>
		<description><![CDATA[This was giving me problems. This solved it.

 { :action => ‘update’, :id => @product.id } do &#124;f&#124; %>



     ‘form’, :locals => { :f => f } %>


Save Listing

]]></description>
			<content:encoded><![CDATA[<p>This was giving me problems. <a href="http://blog.vixiom.com/2006/10/21/use-a-partial-form-with-form_for/">This solved it</a>.</p>
<pre>
<% form_for :product, @product, :url => { :action => ‘update’, :id => @product.id } do |f| %>

<!–[form:product]–>
<div id=‘container‘>
    <%= render :partial => ‘form’, :locals => { :f => f } %>
</div>

<button type=“submit”>Save Listing</button>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/193/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to rewrite urls with nginx</title>
		<link>http://scottmotte.com/archives/189</link>
		<comments>http://scottmotte.com/archives/189#comments</comments>
		<pubDate>Wed, 13 Aug 2008 20:41:37 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=189</guid>
		<description><![CDATA[Nginx rewrite module
Basically, it uses regular expressions so here&#8217;s a good cheat sheet for regular expressions.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://wiki.codemongers.com/NginxHttpRewriteModule">Nginx rewrite module</a></p>
<p>Basically, it uses regular expressions so here&#8217;s a <a href="http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/">good cheat sheet for regular expressions</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/189/feed</wfw:commentRss>
		</item>
		<item>
		<title>DRYing up your controllers in rails with find_filter plugin</title>
		<link>http://scottmotte.com/archives/185</link>
		<comments>http://scottmotte.com/archives/185#comments</comments>
		<pubDate>Tue, 12 Aug 2008 02:06:10 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=185</guid>
		<description><![CDATA[http://matthewbass.com/2008/08/08/finder_filter-gem-released/
This:

class UsersController < ActionController::Base
  before_filter :find_user, :only => [:show, :edit]

  def show
    # do something with @user
  end

  def edit
    # do something with @user
  end

  def find_user
    @user = User.find(params[:id)
  end
end

to this:

class UsersController < ActionController::Base
  finder_filter :only [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://matthewbass.com/2008/08/08/finder_filter-gem-released/">http://matthewbass.com/2008/08/08/finder_filter-gem-released/</a></p>
<p>This:</p>
<pre>
class UsersController < ActionController::Base
  before_filter :find_user, :only => [:show, :edit]

  def show
    # do something with @user
  end

  def edit
    # do something with @user
  end

  def find_user
    @user = User.find(params[:id)
  end
end
</pre>
<p>to this:</p>
<pre>
class UsersController < ActionController::Base
  finder_filter :only => [:show, :edit]

  def show; end
  def edit; end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/185/feed</wfw:commentRss>
		</item>
		<item>
		<title>Setting up Apache vhost (multiple) websites on slicehost</title>
		<link>http://scottmotte.com/archives/173</link>
		<comments>http://scottmotte.com/archives/173#comments</comments>
		<pubDate>Tue, 05 Aug 2008 20:22:36 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=173</guid>
		<description><![CDATA[First, make sure your dns records are setup. (also, you could just use slicehost&#8217;s article. it&#8217;s the best.)
Login to your slice and setup the directory structure for the site

cd ~/public_html


mkdir -p website.com/{public,private,log,cgi-bin,backup}


cd website.com/public


sudo nano index.html
# put a simple message

Now setup your apache config files

cd /etc/apache2/sites-available


sudo nano website.com
# fill it with your configuration

Here&#8217;s an example config [...]]]></description>
			<content:encoded><![CDATA[<p>First, make sure your dns records are setup. (also, you could just use <a href="http://articles.slicehost.com/2008/4/29/ubuntu-hardy-apache-virtual-hosts-1">slicehost&#8217;s article</a>. it&#8217;s the best.)</p>
<p>Login to your slice and setup the directory structure for the site</p>
<pre>
cd ~/public_html
</pre>
<pre>
mkdir -p website.com/{public,private,log,cgi-bin,backup}
</pre>
<pre>
cd website.com/public
</pre>
<pre>
sudo nano index.html
# put a simple message
</pre>
<p>Now setup your apache config files</p>
<pre>
cd /etc/apache2/sites-available
</pre>
<pre>
sudo nano website.com
# fill it with your configuration
</pre>
<p>Here&#8217;s an <a href="http://pastie.org/247981">example config file</a></p>
<pre>
sudo a2ensite website.com
</pre>
<pre>
sudo /etc/init.d/apache2 reload
</pre>
<p>Test out in your web browser at http://website.com</p>
<p>Then repeat the process for your other site(s).</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/173/feed</wfw:commentRss>
		</item>
		<item>
		<title>Postback action for email</title>
		<link>http://scottmotte.com/archives/168</link>
		<comments>http://scottmotte.com/archives/168#comments</comments>
		<pubDate>Tue, 05 Aug 2008 06:04:24 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=168</guid>
		<description><![CDATA[This is useful for a contact form with ruby on rails. 
See Recipe 33 in Rails Recipes.

  def contact
    if request.post?
      Emailer::deliver_contact_email(params[:email])
      flash[:notice] = "Your email was sent successfully. Thank you for your contact."
    end
  end

]]></description>
			<content:encoded><![CDATA[<p>This is useful for a <a href="http://scottmotte.com/archives/159">contact form with ruby on rails</a>. </p>
<p>See Recipe 33 in Rails Recipes.</p>
<pre>
  def contact
    if request.post?
      Emailer::deliver_contact_email(params[:email])
      flash[:notice] = "Your email was sent successfully. Thank you for your contact."
    end
  end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/168/feed</wfw:commentRss>
		</item>
		<item>
		<title>Contact email form with Ruby on Rails and GMail (plus, reply-to error)</title>
		<link>http://scottmotte.com/archives/159</link>
		<comments>http://scottmotte.com/archives/159#comments</comments>
		<pubDate>Tue, 05 Aug 2008 05:16:23 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=159</guid>
		<description><![CDATA[UPDATE AUGUST 6TH, 2008: Gmail&#8217;s reply-to was failing with the rails action-mailer. It would show the reply-to email as the email from gmail rather than the email address entered by the user. I did the following, and it fixed the reply-to, but now the @from does not work. At least the reply-to works!
sources: rails-send-email-tutorial and [...]]]></description>
			<content:encoded><![CDATA[<p>UPDATE AUGUST 6TH, 2008: Gmail&#8217;s reply-to was failing with the rails action-mailer. It would show the reply-to email as the email from gmail rather than the email address entered by the user. I did the following, and it fixed the reply-to, but now the @from does not work. At least the reply-to works!</p>
<p>sources: <a href="http://www.jonathansng.com/ruby-on-rails/rails-send-email-tutorial/">rails-send-email-tutorial</a> and <a href="http://www.ruby-forum.com/topic/148969">Action-mailer reply-to header</a></p>
<pre>
def contact_email(email_params, sent_at = Time.now)
    # You only need to customize @recipients.
    @recipients = "scott@scottmotte.com"
    @from = 'Does not work'
    @headers['Reply-To'] = "'#{email_params[:name]}' <#{email_params[:email_address]}>"
    @subject    = 'Contact Form'
    @sent_on    = sent_at
    @body["email_email_address"] = email_params[:email_address]
    @body["email_message"] = email_params[:message]
    @body["email_name"] = email_params[:name]
  end
</pre>
<p>&#8211;<br />
This assumes you already have a rails app</p>
<p><strong>Create emailer model</strong></p>
<pre>
script/generate model emailer
</pre>
<p>Edit app/model/emailer.rb</p>
<pre>
class Emailer < ActionMailer::Base
    def contact_email(email_params, sent_at = Time.now)
        # You only need to customize @recipients.
        @recipients = "contact@website.com"
        @from = email_params[:name] + " <" + email_params[:address] + ">"
        @subject = email_params[:subject]
        @sent_on = sent_at
        @body["email_body"] = email_params[:body]
        @body["email_name"] = email_params[:name]
    end
end
</pre>
<p><strong>Create a file called lib/smtp_tls.rb and <a href="http://pastie.org/135270">paste this code</a> into it.</strong></p>
<p><strong>Create config/initializers/mail.rb &#038; put the following in there:</strong></p>
<pre>
#from http://www.prestonlee.com/archives/63
require "smtp_tls"
# from http://www.avnetlabs.com/rails/restful-authentication-with-rails-2
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "gmail.com",
    :authentication => :plain,
    :user_name => "username",
    :password => "password"
}
</pre>
<p><strong>In controller for your contact form add </strong></p>
<pre>
def send_mail
    Emailer::deliver_contact_email(params[:email])
end
</pre>
<p><strong>Create file app/views/emailer/contact_email.html.erb</strong></p>
<pre>
Name:

<%= @email_name %>

Message:

<%= @email_body %>
</pre>
<p><strong>Create form</strong></p>
<pre>
<% form_tag :action => "send_mail" do %>

Name: <%= text_field "email", "name", :size => 30 %>

Email: <%= text_field "email", "address", :size => 30 %>

Subject: <%= text_field "email", "subject", :size => 30 %>

Body: <%= text_area "email", "body", :rows => 8, :cols => 30 %>
<input type="submit" value="Send Email" class="primary" />

<% end %>
</pre>
<p>Resources:<br />
- <a href="http://digitalpardoe.co.uk/blog/show/56">useful but out of date</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/159/feed</wfw:commentRss>
		</item>
		<item>
		<title>Launching your rails app with passenger on slicehost</title>
		<link>http://scottmotte.com/archives/145</link>
		<comments>http://scottmotte.com/archives/145#comments</comments>
		<pubDate>Tue, 05 Aug 2008 04:26:16 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=145</guid>
		<description><![CDATA[Ryan Bates has a very nice video tutorial on installing passenger at modrails.com.
It isn&#8217;t slicehost specific though, so here&#8217;s some help.
For the part where Ryan adds the necessary passenger lines to httpd.conf (the apache config file) instead for slicehost users edit the /etc/apache2/apache2.conf file. 

sudo nano /etc/apache2/apache2.conf

&#038; paste at the end of the file

  [...]]]></description>
			<content:encoded><![CDATA[<p>Ryan Bates has a very nice video tutorial <a href="http://www.modrails.com/">on installing passenger</a> at modrails.com.</p>
<p>It isn&#8217;t slicehost specific though, so here&#8217;s some help.</p>
<p>For the part where Ryan adds the necessary passenger lines to httpd.conf (the apache config file) instead for slicehost users edit the /etc/apache2/apache2.conf file. </p>
<pre>
sudo nano /etc/apache2/apache2.conf
</pre>
<p>&#038; paste at the end of the file</p>
<pre>
   LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2
   PassengerRuby /usr/bin/ruby1.8
</pre>
<p>Then upload your rails app to the public folder like you would php files or index files (assuming you setup your apache like slicehost recommended in <a href="http://articles.slicehost.com/2008/4/29/ubuntu-hardy-apache-virtual-hosts-1">Apache Virtual Hosts #1</a></p>
<p>Finally, make sure you apache sites-available config file is setup correctly (<a href="http://pastie.org/247525">full example</a>). The document root should be something like:</p>
<pre>
DocumentRoot /home/demo/public_html/yoursite.com/public/public
</pre>
<p><small>and yes, that is two publics - the first one is the one as <a href="http://articles.slicehost.com/2007/9/13/multiple-hosts-layout">setup here</a>, and the second is the rails app&#8217;s public folder</small></p>
<p>Also, you might need to restart your apache.</p>
<pre>
sudo /etc/init.d/apache2 reload
</pre>
<p>Useful:<br />
- <a href="http://www.railsgarden.com/2008/04/12/configurating-passenger-mod_rails-on-slicehost-with-ubuntu-710/">Configuring passenger on slicehost by Ben Hughes</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/145/feed</wfw:commentRss>
		</item>
		<item>
		<title>Use wp super cache plugin to make your wordpress blogs run faster and your apache run better</title>
		<link>http://scottmotte.com/archives/142</link>
		<comments>http://scottmotte.com/archives/142#comments</comments>
		<pubDate>Mon, 21 Jul 2008 04:37:56 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=142</guid>
		<description><![CDATA[wp-super-cache
Wordpress site wp-super-cache download
]]></description>
			<content:encoded><![CDATA[<p><a href="http://ocaoimh.ie/wp-super-cache/">wp-super-cache</a><br />
<a href="http://wordpress.org/extend/plugins/wp-super-cache/">Wordpress site wp-super-cache download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/142/feed</wfw:commentRss>
		</item>
		<item>
		<title>Setting up email to work for wordpress on slicehost</title>
		<link>http://scottmotte.com/archives/141</link>
		<comments>http://scottmotte.com/archives/141#comments</comments>
		<pubDate>Mon, 21 Jul 2008 04:17:31 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=141</guid>
		<description><![CDATA[1. Instal postfix

sudo apt-get postfix
or
sudo aptitude install postfix

Say Yes at the prompt.
2. After it&#8217;s finished installing run:

sudo /etc/init.d/postfix restart

]]></description>
			<content:encoded><![CDATA[<p>1. Instal postfix</p>
<pre>
sudo apt-get postfix
or
sudo aptitude install postfix
</pre>
<p>Say Yes at the prompt.</p>
<p>2. After it&#8217;s finished installing run:</p>
<pre>
sudo /etc/init.d/postfix restart
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/141/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to watch your swap on slicehost</title>
		<link>http://scottmotte.com/archives/140</link>
		<comments>http://scottmotte.com/archives/140#comments</comments>
		<pubDate>Mon, 21 Jul 2008 04:09:32 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=140</guid>
		<description><![CDATA[SuperJared has a great post on swap and how to watch it. He also notes that Apache is usually a serious culprit.

vmstat 1 10

]]></description>
			<content:encoded><![CDATA[<p>SuperJared has a <a href="http://superjared.com/entry/double-edged-swap/">great post on swap and how to watch it</a>. He also notes that Apache is usually a serious culprit.</p>
<pre>
vmstat 1 10
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/140/feed</wfw:commentRss>
		</item>
		<item>
		<title>Setting up ssl on nginx on slicehost with ssl_requirement plugin</title>
		<link>http://scottmotte.com/archives/139</link>
		<comments>http://scottmotte.com/archives/139#comments</comments>
		<pubDate>Mon, 21 Jul 2008 00:14:34 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=139</guid>
		<description><![CDATA[1. Purchase ssl certificate at GoDaddy
2. Create temp directory and create the key and csr

mkdir /home/username/temp
cd /home/username/temp
openssl genrsa -des3 -out myssl.key 1024
openssl req -new -key myssl.key -out myssl.csr

For the csr, you will have to enter information. Try to make it match to what you put in GoDaddy&#8217;s ssl form online.
3. Remove the passphrase you just [...]]]></description>
			<content:encoded><![CDATA[<p>1. Purchase ssl certificate at GoDaddy</p>
<p>2. Create temp directory and create the key and csr</p>
<pre>
mkdir /home/username/temp
cd /home/username/temp
openssl genrsa -des3 -out myssl.key 1024
openssl req -new -key myssl.key -out myssl.csr
</pre>
<p>For the csr, you will have to enter information. Try to make it match to what you put in GoDaddy&#8217;s ssl form online.</p>
<p>3. Remove the passphrase you just had to create for reboot reasons with the server<br />
<a href="http://articles.slicehost.com/2007/12/19/ubuntu-gutsy-self-signed-ssl-certificates-and-nginx">See the slicehost tutorial for this</a></p>
<p>4. Copy the contents of myssl.csr to the GoDaddy form to generate the ssl certificate</p>
<pre>
cat myssl.csr
# then copy and paste the resulting text
</pre>
<p>5. For server software drop down box just choose apache, then press continue, and then check your email.</p>
<p>6. The technical contact on the domain name whois information will have to approve the certificate then you will receive an email with details of the certificate. Click the link in that email and on the next screen choose Apache once again. Then click &#8216;Download Signed Certificate&#8217;. You will get a zip file containing to files - your certificate file and the gd_intermediate_bundle.crt. </p>
<p>7. Combine the contents of these files into one file called myssl.crt (from <a href="http://hostingfu.com/article/godaddy-turbossl-certificate-nginx">here</a>) and upload onto your web server at the same place you generated your key and csr - /home/username/temp    I just used my ftp program to do this step.</p>
<p>8. Now we need to copy the relevant files to the /etc/ssl/ directory</p>
<pre>
sudo cp myssl.crt /etc/ssl/certs/
sudo cp myssl.key /etc/ssl/private/
</pre>
<p>9. Now follow the slicehost article for <a href="http://articles.slicehost.com/2007/12/19/ubuntu-gutsy-nginx-ssl-and-vhosts">ssl and vhosts on nginx</a></p>
<p>10. Then I installed the <a href="http://github.com/rails/ssl_requirement/tree/master">ssl_requirement plugin</a> in my app by following the instructions from Advanced Rails Recipe 68.</p>
<p>Note: This required one additional change to my /usr/local/nginx/sites-available/domain.com file. I had to add &#8216;proxy_set_header X_FORWARDED_PROTO https;&#8217; at the top of my location section of the file.</p>
<p>Example:</p>
<pre>
server {
  listen 443;
  ...
  location / {
    proxy_set_header X_FORWARDED_PROTO https;
    ...
  }
}
</pre>
<p>Resources:<br />
- <a href="http://hostingfu.com/article/godaddy-turbossl-certificate-nginx">GoDaddy ssl on gninx</a><br />
- <a href="http://articles.slicehost.com/2007/12/19/ubuntu-gutsy-self-signed-ssl-certificates-and-nginx">SSL certificates on slicehost with nginx</a><br />
- <a href="http://journal.andrewloe.com/2008/7/16/rails-development-with-ssl">Rails development with ssl</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/139/feed</wfw:commentRss>
		</item>
		<item>
		<title>Making Apache run lighter on slicehost</title>
		<link>http://scottmotte.com/archives/138</link>
		<comments>http://scottmotte.com/archives/138#comments</comments>
		<pubDate>Sun, 20 Jul 2008 23:04:19 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=138</guid>
		<description><![CDATA[I run more than 10 sites on a 256mb slice on slicehost - all php, mostly wordpress sites. They are rarely visited sites with the most popular one getting about 300 hits a day.
By changing the mpm_prefork_module I was able to get my slice to run much lighter on memory.

# default

    StartServers [...]]]></description>
			<content:encoded><![CDATA[<p>I run more than 10 sites on a 256mb slice on slicehost - all php, mostly wordpress sites. They are rarely visited sites with the most popular one getting about 300 hits a day.</p>
<p>By changing the mpm_prefork_module I was able to get my slice to run much lighter on memory.</p>
<pre>
# default
<IfModule mpm_prefork_module>
    StartServers                  5
    MinSpareServers           5
    MaxSpareServers          10
    MaxClients                    150
    MaxRequestsPerChild   0
</IfModule>

# to this - thanks to http://forum.slicehost.com/comments.php?DiscussionID=2099#Item_2
<IfModule mpm_prefork_module>
StartServers       3
MinSpareServers    3
MaxSpareServers    3
ServerLimit        50
MaxClients         50
MaxRequestsPerChild  1000
</IfModule>
</pre>
<p>Here&#8217;s the difference in my memory:</p>
<p><strong>Before:</strong></p>
<p><img src="http://scottmotte.com/wp-content/uploads/2008/07/tpicture-1.png" alt="Picture 1.png" border="0" width="500" /></p>
<p><strong>After:</strong><br />
<img src="http://scottmotte.com/wp-content/uploads/2008/07/tpicture-2.png" alt="Picture 2.png" border="0" width="500" /></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/138/feed</wfw:commentRss>
		</item>
		<item>
		<title>Brand new 256 mb slice memory usage</title>
		<link>http://scottmotte.com/archives/133</link>
		<comments>http://scottmotte.com/archives/133#comments</comments>
		<pubDate>Sat, 19 Jul 2008 18:35:54 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=133</guid>
		<description><![CDATA[Here&#8217;s what a brand new 256 mb slice from slicehost looks like for memory on slicehost.

]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s what a brand new 256 mb slice from slicehost looks like for memory on slicehost.</p>
<p><img src="http://scottmotte.com/wp-content/uploads/2008/07/brand-new-empty-slice2.png" alt="brand-new-empty-slice.png" border="0" width="500" /></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/133/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to check your ubuntu version on slicehost</title>
		<link>http://scottmotte.com/archives/131</link>
		<comments>http://scottmotte.com/archives/131#comments</comments>
		<pubDate>Sat, 19 Jul 2008 00:47:01 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=131</guid>
		<description><![CDATA[You can check your ubuntu version on slicehost with the following command in your terminal window.

sudo lsb_release -a

or here&#8217;s another way to do it from a slicehost article

cat /etc/lsb-release

]]></description>
			<content:encoded><![CDATA[<p>You can check your ubuntu version on slicehost with the following command in your terminal window.</p>
<pre>
sudo lsb_release -a
</pre>
<p>or here&#8217;s another way to do it <a href="http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-2">from a slicehost article</a></p>
<pre>
cat /etc/lsb-release
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/131/feed</wfw:commentRss>
		</item>
		<item>
		<title>Using google charts api with rails (googlechart gem)</title>
		<link>http://scottmotte.com/archives/130</link>
		<comments>http://scottmotte.com/archives/130#comments</comments>
		<pubDate>Fri, 18 Jul 2008 02:52:25 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=130</guid>
		<description><![CDATA[I opted to use the googlechart gem (Google Charts) because the website was nicely designed and had numerous examples. It also seemed to currently have the most development around it. On github it had the most recent commit. This guy also decided on the googlecharts gem.

gem sources -a http://gems.github.com/
sudo gem install googlecharts

Then add the following [...]]]></description>
			<content:encoded><![CDATA[<p>I opted to use the googlechart gem (<a href="http://googlecharts.rubyforge.org/">Google Charts</a>) because the website was nicely designed and had numerous examples. It also seemed to currently have the most development around it. On github it had the most recent commit. <a href="http://chrisolsen.org/2008/01/26/google-charts-with-rails/">This guy</a> also decided on the googlecharts gem.</p>
<pre>
gem sources -a http://gems.github.com/
sudo gem install googlecharts
</pre>
<p>Then add the following to the end of your environment.rb file (for some reason, if you put config.gem &#8216;gchart&#8217; in the new rails 2.0 fashion it does not work.</p>
<pre>
require 'gchart'
</pre>
<p>Then put some code in your view and clean up however you want or need.</p>
<pre>
<%= Gchart.line(:data => [0, 40, 10, 70, 20]) %>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/130/feed</wfw:commentRss>
		</item>
		<item>
		<title>Trying out mongrel instead of thin</title>
		<link>http://scottmotte.com/archives/127</link>
		<comments>http://scottmotte.com/archives/127#comments</comments>
		<pubDate>Wed, 16 Jul 2008 03:38:57 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=127</guid>
		<description><![CDATA[UPDATE: I tried out thin again, but ran only one server for my two small apps, and then ran 3 thin servers for my large app - twinstang.com. Much faster. See the output difference. I&#8217;m sticking with thin, but will stay light on the amount servers from now on. Mongrel was just noticeably slower and [...]]]></description>
			<content:encoded><![CDATA[<p>UPDATE: I tried out thin again, but ran only one server for my two small apps, and then ran 3 thin servers for my large app - twinstang.com. Much faster. See the output difference. I&#8217;m sticking with thin, but will stay light on the amount servers from now on. Mongrel was just noticeably slower and that bothered me.</p>
<p><img src="http://scottmotte.com/wp-content/uploads/2008/07/picture-12.png" alt="Picture 1.png" border="0" width="778" height="167" /></p>
<p><img src="http://scottmotte.com/wp-content/uploads/2008/07/picture-2.png" alt="Picture 2.png" border="0" width="608" height="88" /></p>
<p>I am trying out mongrel instead of thin for one of my apps on my slicehost. I was running 3 apps, but my swap kept getting used slightly. </p>
<p>So far the mongrel is definitely slower than the 2 thin apps running, but my swap is now down to zero as I would like. Maybe mongrel is lighter on the server than thin?</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/127/feed</wfw:commentRss>
		</item>
		<item>
		<title>Passenger (mod_rails) versus Thin on nginx</title>
		<link>http://scottmotte.com/archives/126</link>
		<comments>http://scottmotte.com/archives/126#comments</comments>
		<pubDate>Sun, 13 Jul 2008 16:34:54 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=126</guid>
		<description><![CDATA[Here&#8217;s a good post on Passenger versus Thin, and here is a better benchmark that includes thin on nginx.


Passenger looks to be pretty darn quick. I&#8217;m impressed.
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a good post on <a href="http://izumi.plan99.net/blog/index.php/2008/03/31/benchmark-passenger-mod_rails-vs-mongrel-vs-thin/">Passenger versus Thin</a>, and here is a <a href="http://ariekanarie.nl/archives/51/mod_rails-vs-thin-vs-ebb-vs-mongrel">better benchmark that includes thin on nginx.</a></p>
<p><img src="http://scottmotte.com/wp-content/uploads/2008/07/image001.png" alt="image001.png" border="0" width="482" height="289" /></p>
<p><img src="http://scottmotte.com/wp-content/uploads/2008/07/passenger-mongrel-thin-benchmark.png" alt="passenger_mongrel_thin_benchmark.png" border="0" width="470" height="292" /></p>
<p>Passenger looks to be pretty darn quick. I&#8217;m impressed.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/126/feed</wfw:commentRss>
		</item>
		<item>
		<title>How to add additional routes to restful rails controllers</title>
		<link>http://scottmotte.com/archives/123</link>
		<comments>http://scottmotte.com/archives/123#comments</comments>
		<pubDate>Sun, 13 Jul 2008 00:26:29 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=123</guid>
		<description><![CDATA[In your controller file

  def test_email
	...#content here
  end

In your routes.rb file

map.resources :flowers, :collection => { :test_email => :get}

]]></description>
			<content:encoded><![CDATA[<p>In your controller file</p>
<pre>
  def test_email
	...#content here
  end
</pre>
<p>In your routes.rb file</p>
<pre>
map.resources :flowers, :collection => { :test_email => :get}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/123/feed</wfw:commentRss>
		</item>
		<item>
		<title>Using paperclip for image attachments in rails</title>
		<link>http://scottmotte.com/archives/122</link>
		<comments>http://scottmotte.com/archives/122#comments</comments>
		<pubDate>Sat, 12 Jul 2008 21:55:58 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=122</guid>
		<description><![CDATA[Advantage to using paperclip: you don&#8217;t have to create separate model for images and then create a join relationship like with attachment_fu
What you&#8217;ll need:
- the paperclip plugin: run the following from your terminal in your rail&#8217;s project root folder:

script/plugin install git://github.com/thoughtbot/paperclip.git

Useful tutorials:
- Paperclip project page
- Paperclip original tutorial
- Paperclip more useful tutorial
How to:
1. Create a [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Advantage to using paperclip:</strong> you don&#8217;t have to create separate model for images and then create a join relationship like with attachment_fu</p>
<p><strong>What you&#8217;ll need:</strong><br />
- the paperclip plugin: run the following from your terminal in your rail&#8217;s project root folder:</p>
<pre>
script/plugin install git://github.com/thoughtbot/paperclip.git
</pre>
<p><strong>Useful tutorials:</strong><br />
- <a href="http://thoughtbot.com/projects/paperclip">Paperclip project page</a><br />
- <a href="http://giantrobots.thoughtbot.com/2008/3/18/for-attaching-files-use-paperclip">Paperclip original tutorial</a><br />
- <a href="http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/">Paperclip more useful tutorial</a></p>
<p><strong>How to:</strong></p>
<p>1. Create a new migration file: script/generate migration add_images_to_flowers and rake db:migrate</p>
<pre>
class AddImageToFlowers < ActiveRecord::Migration
  def self.up
    add_column :flowers, :image_file_name, :string
    add_column :flowers, :image_content_type, :string
    add_column :flowers, :image_file_size, :integer
  end

  def self.down
    remove_column :flowers, :image_file_size
    remove_column :flowers, :image_content_type
    remove_column :flowers, :image_file_name
  end
end
</pre>
<p>2. Change your form to use multipart. (I don&#8217;t see why http just doesn&#8217;t default to multipart with its forms. It&#8217;s seems a little ridiculous to have to add multi-part)</p>
<pre>
	<% form_for [:admin, @flower], :html => { :multipart => true } do |f| %> #if you put your new/edit under admin/flowers_controller.rb
	or
	<% form_for @flower, :html => { :multipart => true } do |f| %>
</pre>
<p>3. Add the file field to the form</p>
<pre>
<%= f.label :image %>
<%= f.file_field :image %> #as you can see if uses the pre-name to the above migration fields 'image'. This is one smart plugin.
</pre>
<p>4. In your model add the following</p>
<pre>
class Flower < ActiveRecord::Base

  # Paperclip
  has_attached_file :image,
    :styles => {
      :thumb=> "100x100#",
      :small  => "150x150>",
      :medium => "300x300>" }

end
</pre>
<p>5. Now try uploading an image and check your database to see that it got added. You&#8217;ll also see that in your public view it added a folder called images (plural of image) with a subfolder defined by the id of the post, and with more subfolders for the different sizes of your image as you specified in the above model (thumb, small, medium).</p>
<p><img src="http://scottmotte.com/wp-content/uploads/2008/07/picture-11.png" alt="Picture 1.png" border="0" width="157" height="100" /></p>
<p>Pretty darn cool, if you ask me.</p>
<p>This is a great tool for simple single image adding to a model.</p>
<p>6. Add it to your views. This is pretty easy just call the following: </p>
<pre>
<%= image_tag @flower.image.url %>
<%= image_tag @flower.image.url(:thumb) %>
<%= image_tag @flower.image.url(:small) %>
<%= image_tag @flower.image.url(:medium) %>
</pre>
<p>I think you get the idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/122/feed</wfw:commentRss>
		</item>
		<item>
		<title>Reagan Quotes</title>
		<link>http://scottmotte.com/archives/120</link>
		<comments>http://scottmotte.com/archives/120#comments</comments>
		<pubDate>Fri, 11 Jul 2008 16:44:47 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=120</guid>
		<description><![CDATA[
&#8220;We don&#8217;t celebrate &#8216;dependence (on the government) day&#8217; July 4th, we celebrate Independence Day!&#8221;
&#8220;I can&#8217;t help thinking, while much of the 20th century saw the rise of the federal government, the 21st Century will be the century of the states. I have always believed that America is strongest and freest and happiest when it is [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://scottmotte.com/wp-content/uploads/2008/07/reagan.jpg" alt="reagan.jpg" border="0" width="300" align="right" /></p>
<p>&#8220;We don&#8217;t celebrate &#8216;dependence (on the government) day&#8217; July 4th, we celebrate Independence Day!&#8221;</p>
<p>&#8220;I can&#8217;t help thinking, while much of the 20th century saw the rise of the federal government, the 21st Century will be the century of the states. I have always believed that America is strongest and freest and happiest when it is truest to the wisdom of its founders.&#8221;</p>
<p>&#8220;Too often, character assassination has replaced debate in principle in Washington, D.C. Destroy someone&#8217;s reputation and you don&#8217;t have to talk about what he stands for.&#8221;</p>
<p>&#8220;One thing our Founding Fathers could not foresee&#8230;they were farmers, professional men, businessmen giving of their time and effort to a dream and an idea that became a country&#8230;was (today) a nation governed by professional politicians who had a vested interest in getting re-elected. They probably envisioned a fellow serving a couple of hitches and then looking eagerly forward to getting back to the farm.&#8221;</p>
<p>&#8220;The image of George Washington kneeling in prayer in the snow is one of the most famous in American history. He personified a people who knew it was not enough to depend on their own courage and goodness, they must also seek help from God, their Father and Preserver.&#8221;</p>
<p>&#8220;We make a living by what we get, we make a life by what we give.&#8221;</p>
<p>&#8220;How can we not believe in the greatness of America? How can we not do what is right and needed to preserve this last best hope of man on earth? After all our struggles to restore America, to revive confidence in our country, hope for our future - after all our hard won victories earned through the patience and courage of every citizen- we cannot, must not and will not turn back. We will finish our job. How could we do less? We&#8217;re Americans.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/120/feed</wfw:commentRss>
		</item>
		<item>
		<title>Automate mysql backup with amazon s3</title>
		<link>http://scottmotte.com/archives/117</link>
		<comments>http://scottmotte.com/archives/117#comments</comments>
		<pubDate>Tue, 08 Jul 2008 06:12:11 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=117</guid>
		<description><![CDATA[This tutorial is awesome for automating mysql backup with amazon s3. Plus, it is from a slicehost user - eve n more awesomeness.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://therailscoder.typepad.com/the_rails_coder_ruby_on_r/2008/04/automatic-mysql.html">This tutorial is awesome for automating mysql backup with amazon s3.</a> Plus, it is from a slicehost user - eve n more awesomeness.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/117/feed</wfw:commentRss>
		</item>
		<item>
		<title>RubyScript2Exe - turning your ruby script/app into a .exe on windows</title>
		<link>http://scottmotte.com/archives/116</link>
		<comments>http://scottmotte.com/archives/116#comments</comments>
		<pubDate>Tue, 08 Jul 2008 00:09:19 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=116</guid>
		<description><![CDATA[So I created a useful little ruby script on my windows machine, and wanted to turn it into a .exe script. This way I could run it under my windows system scheduler once a day.
I followed this tutorial for setting up your ruby script as a .exe on windows.
RubyScript2Exe docs
]]></description>
			<content:encoded><![CDATA[<p>So I created a useful little ruby script on my windows machine, and wanted to turn it into a .exe script. This way I could run it under my windows system scheduler once a day.</p>
<p>I followed this tutorial for <a href="http://rubyonwindows.blogspot.com/2007/09/compiling-your-ruby-app-with.html">setting up your ruby script as a .exe on windows.</a></p>
<p><a href="http://www.erikveen.dds.nl/rubyscript2exe/">RubyScript2Exe docs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/116/feed</wfw:commentRss>
		</item>
		<item>
		<title>Useful scripts with mechanize, hpricot, and htmldoc</title>
		<link>http://scottmotte.com/archives/115</link>
		<comments>http://scottmotte.com/archives/115#comments</comments>
		<pubDate>Sun, 06 Jul 2008 18:10:27 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=115</guid>
		<description><![CDATA[Here are some useful scripts with mechanize, hpricot, and htmldoc
First, install mechanize and hpricot and htmldoc (pdfs)

gem install hpricot
gem install mechanize
gem install htmldoc

Save web page as pdf with mechanize and htmldoc

require 'rubygems'
require 'mechanize'
require 'htmldoc'

agent = WWW::Mechanize.new
agent.user_agent_alias = 'Mac FireFox'
agent.redirect_ok = true

page = agent.get('http://scottmotte.com/archive')
pdf = PDF::HTMLDoc.new

pdf.set_option :outfile, "~/Desktop/outfile.pdf"
pdf.set_option :bodycolor, :white
pdf.set_option :links, true

pdf  positions)
f.set_fields( 'fund_value[cash]' => [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some useful scripts with mechanize, hpricot, and htmldoc</p>
<p>First, install mechanize and hpricot and htmldoc (pdfs)</p>
<pre>
gem install hpricot
gem install mechanize
gem install htmldoc
</pre>
<h3>Save web page as pdf with mechanize and htmldoc</h3>
<pre>
require 'rubygems'
require 'mechanize'
require 'htmldoc'

agent = WWW::Mechanize.new
agent.user_agent_alias = 'Mac FireFox'
agent.redirect_ok = true

page = agent.get('http://scottmotte.com/archive')
pdf = PDF::HTMLDoc.new

pdf.set_option :outfile, "~/Desktop/outfile.pdf"
pdf.set_option :bodycolor, :white
pdf.set_option :links, true

pdf << page.body

if pdf.generate
  puts "Hallelujah"
else
  puts 'No Joy'
end
</pre>
<h3>Log into a website with mechanize, save some data with hpricot, and then insert that data into another website</h3>
<p>For this one, I wanted to be able to automatically save my stock values each day, and insert them into my personal application where I graph them on a daily basis. I was tired of doing this by hand so I used mechanize and hpricot to automate the process. (I just need to set this up on schedule as a cron task now.)</p>
<pre>
require 'rubygems'
require 'mechanize'
require 'hpricot'
require 'open-uri'

agent = WWW::Mechanize.new
agent.user_agent_alias = 'Mac FireFox'
agent.redirect_ok = true

## FIRST TIME ##
page = agent.get('http://scottrade.com')

login_form = page.forms.first
login_form.account = '*****your account number*****'
login_form.password = '*****your password*****'
page = agent.submit(login_form)

link = page.links.text("My Account")
page = link.click

doc = Hpricot.parse(page.body)

# positions
positions = (doc/'span#DetailedBalances_lblCashStocksMutFdsCDBonds').inner_html
positions = positions.gsub( "$", '') #strip the dollar sign
positions = positions.gsub( ",", '') #strip the commas

# cash
cash = (doc/'span#DetailedBalances_lblCashTotalMoneyBalance').inner_html
cash = cash.gsub( "$", '')
cash = cash.gsub( ",", '')

# total
total = (doc/'span#DetailedBalances_lblCashTotalAcctValue').inner_html
total = total.gsub("$", '')
total = total.gsub(",", '')

page = agent.get('/Default.aspx?log=off') #log out

# now insert that content
page = agent.get('http://app.scottmotte.com')

login_form = page.forms.first
login_form.login = '***my username***'
login_form.password = '***my password***'
page = agent.submit(login_form)

page = agent.get('/daily_stock_values/new')

f = page.forms.first
f.set_fields( 'fund_value[positions]' => positions)
f.set_fields( 'fund_value[cash]' => cash)
f.set_fields( 'fund_value[total]' => total)
# the date field gets inserted automatically using rails created_at method. The app is built in rails.
page = agent.submit(f)

page = agent.get('/logout')
</pre>
<h3>Get an image from a website and save it locally</h3>
<pre>
require 'rubygems'
require 'mechanize'
require 'hpricot'
require 'open-uri'
require 'uri'

@agent = WWW::Mechanize.new
@agent.user_agent_alias = 'Mac Safari'
@agent.redirect_ok = true
page = @agent.get("http://intype.info/home/trailers/alpha_3/bg.png")
myStr = page.body
aFile = File.new("mypicture.gif", "wb")
aFile.write(myStr)
aFile.close
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/115/feed</wfw:commentRss>
		</item>
		<item>
		<title>Installing Ruby on Windows and Setting up Watir on Windows</title>
		<link>http://scottmotte.com/archives/114</link>
		<comments>http://scottmotte.com/archives/114#comments</comments>
		<pubDate>Sun, 06 Jul 2008 00:14:03 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=114</guid>
		<description><![CDATA[This is really poorly written and more of a mind dump than anything. Use it at your own risk. I eventually gave up on cygwin. It caused me some headaches. Instead, I did the following:
1. Installed ruby for windows using the one-click installer from ruby-lang.org (for some reason I had to install under the Administrator [...]]]></description>
			<content:encoded><![CDATA[<p>This is really poorly written and more of a mind dump than anything. Use it at your own risk. I eventually gave up on cygwin. It caused me some headaches. Instead, I did the following:</p>
<p>1. Installed ruby for windows using the <a href="http://www.ruby-lang.org/en/downloads/">one-click installer from ruby-lang.org</a> (for some reason I had to install under the Administrator account on my windows machine)</p>
<p>2. Installed <a href="http://sourceforge.net/project/showfiles.php?group_id=43764"><br />
windows console 2.0</a>. It beats using the dos command, but it still is poor compared to the *nix command line. </p>
<pre>
# helpful commands
cd (just like *nix)
dir (similar to ls -al in *nix)
</pre>
<p>3. Opened up console and typed:</p>
<pre>
irb
puts 'hello world'
exit
</pre>
<p>Good, ruby seems to be working.</p>
<p>3. Installed <a href="http://intype.info/home/index.php">intype</a> as my text editor of choice.</p>
<p>4. Installed watir</p>
<pre>
gem install watir
</pre>
<p>5. Then after trying watir, I wasn&#8217;t really all that happy with it so I decided to go with using a combination of mechanize and hpricot. See <a href="http://scottmotte.com/archives/115">useful scripts with mechanize and hpricot</a>.  </p>
<p>&#8212;<br />
&#8212;<br />
<strong>Mind dump</strong><br />
&#8212;<br />
<strike>1. Install ruby for windows (<a href="http://www.ruby-lang.org/en/downloads/">use the ruby one-click installer from ruby-lang.org</a>) (i just installed to c:\ruby. it will take about 5 minutes to complete the installation. while you&#8217;re waiting <a href="http://intype.info/home/index.php">download intype</a> or your text editor of choice for windows. e-texteditor comes recommended but will cost you $30 bucks.)</strike> Don&#8217;t do any of this or your cygwin with ruby will not function correctly.</p>
<p>2. Install cygwin (this will emulate *nix-like command terminals. The windows dos command console is a pain to work in and most all the examples you will find online are for *nix)</p>
<p>a. Download the setup.exe from <a href="http://cygwin.com">Cygwin.com</a> and then run setup.exe<br />
b. Install in c:\cygwin<br />
c. Install the local package directory to your desktop<br />
d. Install from direct connection<br />
e. Choose an available download site and press next<br />
f. For the Select Packages make sure you do the following:<br />
   i. Go to Devel -> ruby, and change &#8216;Skip&#8217; to 1.8.7 by clicking on the &#8216;Skip&#8217; on the ruby line (here&#8217;s a tutorial with <a href="http://physionet.org/physiotools/cygwin/">screenshots</a> (but ignore the packages being installed. they won&#8217;t apply to you.))<br />
   ii. Go to Devel -> and install all the lines that start with gcc by once again clicking on the prospective line&#8217;s &#8216;Skip&#8217;<br />
   iii. Go to Devel -> make and install by doing the same as above<br />
   iv. Go to Devel -> openssl-devel and install by doing the same as above<br />
   v. Under Database -> sqlite you might as well do the same since if you run rails one day you&#8217;ll want it<br />
   vi. Under Net -> openssl install<br />
   vii. Under Net -> openssh install<br />
   viii. Under Editors -> vim install<br />
   ix. Under Editors -> nano install<br />
   x. Under Net -> curl install<br />
   xi. Under Shells -> rxvts install all of them<br />
   xii. Under System -> ping install<br />
   xiii. Under Web -> wget install<br />
g. Then click next and wait for everything to download. It will probably take about 10 minutes. </p>
<p>Open up Cygwin and type in the prompt:</p>
<pre>
irb

puts 'hello world'

exit
</pre>
<p>As long as that didn&#8217;t throw any errors than your ruby is setup correctly. Time to get watir. Wait first we have to install rubygems.</p>
<p>3. Install ruby gems<br />
a. Go to <a href="http://rubyforge.org/frs/?group_id=126">the rubyforge ruby gems installation page</a> and download the latest version as a tgz file. (rubygems-1.2.0.tgz at the time of this writing)<br />
b. Save this file to My computer c:\cygwin\home\user name\sources   (you&#8217;ll need to create the directory sources)<br />
c. Open up cygwin and do the following</p>
<pre>
cd ~/sources
tar -pxzf rubygems-1.2.0.tar
cd rubygems-1.2.0
ruby setup.rb
</pre>
<p>4. Install watir</p>
<pre>
gem install watir
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/114/feed</wfw:commentRss>
		</item>
		<item>
		<title>Scrubyt perks and rules</title>
		<link>http://scottmotte.com/archives/113</link>
		<comments>http://scottmotte.com/archives/113#comments</comments>
		<pubDate>Thu, 03 Jul 2008 23:39:11 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=113</guid>
		<description><![CDATA[-It will skip over tbody for xpaths. Don&#8217;t include it in your xpath.

# correct
content '//body/table/tr/td

# incorrect
content '//body/table/tbody/tr/td

-It will skip over font[@size=n] but not over just plain font
-extractor.to_xml will output to the xml you specify within the: 

extractor = Scrubyt::Extractor.define do
..
end

-extractor.to_text i&#8217;m not sure how to work
]]></description>
			<content:encoded><![CDATA[<p>-It will skip over tbody for xpaths. Don&#8217;t include it in your xpath.</p>
<pre>
# correct
content '//body/table/tr/td

# incorrect
content '//body/table/tbody/tr/td
</pre>
<p>-It will skip over font[@size=n] but not over just plain font</p>
<p>-extractor.to_xml will output to the xml you specify within the: </p>
<pre>
extractor = Scrubyt::Extractor.define do
..
end
</pre>
<p>-extractor.to_text i&#8217;m not sure how to work</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/113/feed</wfw:commentRss>
		</item>
		<item>
		<title>Scrubyt screen scraping tutorials</title>
		<link>http://scottmotte.com/archives/112</link>
		<comments>http://scottmotte.com/archives/112#comments</comments>
		<pubDate>Thu, 03 Jul 2008 23:14:47 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=112</guid>
		<description><![CDATA[I am beginning to use scrubyt gem and in my opinion the documentation and examples are pretty bad. The name isn&#8217;t the greatest either. It&#8217;s difficult to type so be careful in the following examples. (should have just called it scruby or scrubby or something. the t is annoying.)
**However**, I am starting to understand how [...]]]></description>
			<content:encoded><![CDATA[<p>I am beginning to use scrubyt gem and in my opinion the documentation and examples are pretty bad. The name isn&#8217;t the greatest either. It&#8217;s difficult to type so be careful in the following examples. (should have just called it scruby or scrubby or something. the t is annoying.)</p>
<p>**However**, I am starting to understand how scrubyt works, and it really is one heck of an awesome and powerful gem.</p>
<p>I hope the following small scripts and basic tutorial will help speed your learning process for scrubyt. </p>
<p><strong>Install Scrubyt</strong></p>
<pre>
sudo gem install scrubyt
</pre>
<p><strong>Create your first scrubyt script</strong><br />
Create a .rb file to test scrubyt. Call it scrubyt_example.rb and save it in your documents/scripts folder or documents/ruby folder or wherever you like.</p>
<p>Edit that file with the following code</p>
<pre>
require 'rubygems'
require 'scrubyt'

data = Scrubyt::Extractor.define do
  fetch 'http://google.com'
  title '//head/title'
end

data.to_xml.write($stdout, 1)
</pre>
<p><strong>Test run the file</strong><br />
In your terminal cd to the folder where you saved the scrubyt_example.rb</p>
<pre>
cd ~/documents/code/ruby
</pre>
<p>&#038; then run the file with the ruby command in your terminal from inside that folder</p>
<pre>
ruby scrubyt_example.rb
</pre>
<p>Ok, way to go, you just learned how to use the xPath (//head/title) to define the part of the website page you wanted. You can get deeper and deeper into the site content by creating just about any xPath you want (i.e. //body/title/table/tr/td).</p>
<p>NOTE: I am using firebug in firefox 3 to view the path to these html elements. You could just as easily view source, but there is a good chance you&#8217;ll make a mistake. I recommend using firebug.</p>
<p>Now let&#8217;s get a little more complicated by basically creating a for loop with scrubyt.</p>
<pre>
require 'rubygems'
require 'scrubyt'

extractor = Scrubyt::Extractor.define do
  # go to website
  fetch 'http://scottmotte.com/archive'
  # move down to the ul and call it content and for each ul *do* the following
  content '//body/div/div/div/ul' do
    # grab the content of the li element and call it post
    post '/li'
  end
end
puts extractor.to_xml
</pre>
<p>This script loops through all the li items on my archive page at <a href="http://scottmotte.com/archive">http://scottmotte.com/archive</a></p>
<p>Ok, way to go. Now let&#8217;s learn how to login somewhere. This is actually pretty darn easy with scrubyt. We are also going to click a link to change pages, and spit out the url of the page so that we know we have actually changed pages. (Of course, you&#8217;ll need to change this to a website you have login access to [just don't try gmail, it uses heavy javascript and so there is another trick to doing that that I haven't tried yet. Scrubyt is not good at handling javascript because www::mechanize is not.]. As well, your fill_textfield names will be different depending on the website. For example, in youtube they are simply &#8216;username&#8217; and &#8216;password&#8217;. View source or use firebug to find out.)</p>
<pre>
# example from http://scrubyt.rubyforge.org/files/README.html
require "rubygems"
require "scrubyt"

data = Scrubyt::Extractor.define do

  fetch 'http://www.investors.com/logOffConfirm.aspx?REG=un'
  fill_textfield 'htmUserName', '***your username***'
  fill_textfield 'htmPassword', '***your password***'
  submit

  click_link 'Today In IBD'
  click_link 'Today In IBD'

  click_link 'The Big Picture'

  url "href", :type => :attribute #this part isn't technically correct
end

data.to_xml.write($stdout, 1)
</pre>
<p>Note: for some reason, I had to do the click_link &#8216;Today In IBD&#8217; twice. This seems to be a bug or something weird with investors.com. Either way, you might have a similar problem so try doing the click_link twice.</p>
<p>Note 2: the url &#8220;href&#8221;, :type => :attribute isn&#8217;t technically correct, but it will spit out the present url in your terminal. Just don&#8217;t use it for production or in a rails app yet. I&#8217;m still learning and figuring out how to make this correct.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/112/feed</wfw:commentRss>
		</item>
		<item>
		<title>Top Rails plugins</title>
		<link>http://scottmotte.com/archives/111</link>
		<comments>http://scottmotte.com/archives/111#comments</comments>
		<pubDate>Thu, 03 Jul 2008 17:27:48 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=111</guid>
		<description><![CDATA[10 must have rails plugins
]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.thinkrelevance.com/2008/6/16/10-must-have-rails-plugins">10 must have rails plugins</a></p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/111/feed</wfw:commentRss>
		</item>
		<item>
		<title>scrubyt rubyinline error on install</title>
		<link>http://scottmotte.com/archives/110</link>
		<comments>http://scottmotte.com/archives/110#comments</comments>
		<pubDate>Thu, 03 Jul 2008 16:17:35 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=110</guid>
		<description><![CDATA[I was getting the following error after doing sudo gem install scrubyt and trying to run a scrubyt script

can't activate RubyInline (= 3.6.3), already activated RubyInline-3.7.0] (Gem::Exception)

I found this solution for how to fix the Scrubyt RubyInline version error, and it worked great. 

sudo gem uninstall RubyInline -v 3.7.0

]]></description>
			<content:encoded><![CDATA[<p>I was getting the following error after doing sudo gem install scrubyt and trying to run a scrubyt script</p>
<pre>
can't activate RubyInline (= 3.6.3), already activated RubyInline-3.7.0] (Gem::Exception)
</pre>
<p>I found this solution for <a href="http://www.rubynaut.net/articles/2007/10/16/scrubyt-on-rails">how to fix the Scrubyt RubyInline version error</a>, and it worked great. </p>
<pre>
sudo gem uninstall RubyInline -v 3.7.0
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/110/feed</wfw:commentRss>
		</item>
		<item>
		<title>Thank you MarsEdit</title>
		<link>http://scottmotte.com/archives/109</link>
		<comments>http://scottmotte.com/archives/109#comments</comments>
		<pubDate>Thu, 03 Jul 2008 04:55:58 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=109</guid>
		<description><![CDATA[MarsEdit has been awesome. I have never posted so many solutions to ruby on rails coding problems before. The desktop editor makes it so much easier to do so that I actually quite enjoy it. If you are having trouble motivating yourself to post blog entries (especially if you&#8217;re a programmer wishing to document your [...]]]></description>
			<content:encoded><![CDATA[<p>MarsEdit has been awesome. I have never posted so many solutions to ruby on rails coding problems before. The desktop editor makes it so much easier to do so that I actually quite enjoy it. If you are having trouble motivating yourself to post blog entries (especially if you&#8217;re a programmer wishing to document your solutions to problems so that you don&#8217;t find yourself forgetting how to do things) go get <a href="http://www.red-sweater.com/marsedit/">MarsEdit</a>. It&#8217;s great.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottmotte.com/archives/109/feed</wfw:commentRss>
		</item>
		<item>
		<title>Getting stock quote data into your rails app</title>
		<link>http://scottmotte.com/archives/108</link>
		<comments>http://scottmotte.com/archives/108#comments</comments>
		<pubDate>Thu, 03 Jul 2008 04:51:27 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://scottmotte.com/?p=108</guid>
		<description><![CDATA[I needed a way to get stock quote data into my rails app. I decided to go with the yahoofinance gem.
1. install it: sudo gem install yahoofinance
2. require it in your environment file - for rails 2.1 do config.gem &#8216;yahoofinance&#8217;
3. Use the following code to add it to your database (make sure you have a [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a way to get stock quote data into my rails app. I decided to go with the yahoofinance gem.</p>
<p>1. install it: sudo gem install yahoofinance<br />
2. require it in your environment file - for