<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>HappyCoder - Home</title>
  <id>tag:topher.88-mph.net,2008:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.7.3">Mephisto Noh-Varr</generator>
  <link href="http://topher.88-mph.net/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://topher.88-mph.net/" rel="alternate" type="text/html"/>
  <updated>2008-05-12T15:00:51Z</updated>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2008-05-12:14</id>
    <published>2008-05-12T15:00:00Z</published>
    <updated>2008-05-12T15:00:51Z</updated>
    <category term="Rails"/>
    <link href="http://topher.88-mph.net/2008/5/12/railsconf-2008" rel="alternate" type="text/html"/>
    <title>Railsconf 2008</title>
<content type="html">
            &lt;p&gt;I will be at Railsconf 2008 at Portland. I still haven&#8217;t finalized the sessions I&#8217;m attending but I&#8217;m sure it will be great.&lt;/p&gt;


	&lt;p&gt;&lt;a href=&quot;http://conferences.oreilly.com/rails/&quot;&gt;
&lt;img title=&quot;RailsConf 2008&quot; src=&quot;http://conferences.oreillynet.com/banners/rails/promote/336x280.gif&quot; height=&quot;280&quot; alt=&quot;RailsConf 2008&quot; width=&quot;336&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-11-13:12</id>
    <published>2007-11-13T15:49:00Z</published>
    <updated>2007-11-13T15:50:23Z</updated>
    <category term="Rails"/>
    <link href="http://topher.88-mph.net/2007/11/13/notes-on-migrations" rel="alternate" type="text/html"/>
    <title>Notes on migrations</title>
<content type="html">
            &lt;p&gt;If you add columns to a model, and you want to use that model, call Base#reset_column_information.&lt;/p&gt;


	&lt;p&gt;If you save a model in a migration, and if you do not want the timestamps (created_at, updated_at) to be updated, put ActiveRecord::Base.record_timestamps = false.&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;25&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;AddLastCommentAtToTopic&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Migration&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;Topic&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    has_many &lt;span class=&quot;sy&quot;&gt;:posts&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;Post&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.up&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;.record_timestamps = &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    add_column &lt;span class=&quot;sy&quot;&gt;:topics&lt;/span&gt; &lt;span class=&quot;sy&quot;&gt;:last_comment_at&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:datetime&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;Topic&lt;/span&gt;.reset_column_information&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;Topic&lt;/span&gt;.find(&lt;span class=&quot;sy&quot;&gt;:all&lt;/span&gt;).each &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |topic|&lt;tt&gt;
&lt;/tt&gt;      topic = topic.posts.find(&lt;span class=&quot;sy&quot;&gt;:first&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:order&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;last_comment_at DESC&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; topic&lt;tt&gt;
&lt;/tt&gt;        topic.last_comment_at  = post.last_comment_at&lt;tt&gt;
&lt;/tt&gt;        topic.save&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;.record_timestamps = &lt;span class=&quot;pc&quot;&gt;true&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.down&lt;tt&gt;
&lt;/tt&gt;    remove_column &lt;span class=&quot;sy&quot;&gt;:topics&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:last_comment_at&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-11-11:11</id>
    <published>2007-11-11T16:38:00Z</published>
    <updated>2007-11-11T16:50:59Z</updated>
    <category term="Rails"/>
    <link href="http://topher.88-mph.net/2007/11/11/send-emails-in-development-environment-using-gmail" rel="alternate" type="text/html"/>
    <title>Send emails in development environment using Gmail</title>
<content type="html">
            &lt;p&gt;If you don&#8217;t have a mail server in your development machine, you can use Gmail. Put the following code in &lt;span class=&quot;caps&quot;&gt;RAILS&lt;/span&gt;_ROOT/lib/smtp_tls.rb&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;25&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;27&lt;tt&gt;
&lt;/tt&gt;28&lt;tt&gt;
&lt;/tt&gt;29&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;30&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;31&lt;tt&gt;
&lt;/tt&gt;32&lt;tt&gt;
&lt;/tt&gt;33&lt;tt&gt;
&lt;/tt&gt;34&lt;tt&gt;
&lt;/tt&gt;35&lt;tt&gt;
&lt;/tt&gt;36&lt;tt&gt;
&lt;/tt&gt;37&lt;tt&gt;
&lt;/tt&gt;38&lt;tt&gt;
&lt;/tt&gt;39&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;40&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;41&lt;tt&gt;
&lt;/tt&gt;42&lt;tt&gt;
&lt;/tt&gt;43&lt;tt&gt;
&lt;/tt&gt;44&lt;tt&gt;
&lt;/tt&gt;45&lt;tt&gt;
&lt;/tt&gt;46&lt;tt&gt;
&lt;/tt&gt;47&lt;tt&gt;
&lt;/tt&gt;48&lt;tt&gt;
&lt;/tt&gt;49&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;50&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;51&lt;tt&gt;
&lt;/tt&gt;52&lt;tt&gt;
&lt;/tt&gt;53&lt;tt&gt;
&lt;/tt&gt;54&lt;tt&gt;
&lt;/tt&gt;55&lt;tt&gt;
&lt;/tt&gt;56&lt;tt&gt;
&lt;/tt&gt;57&lt;tt&gt;
&lt;/tt&gt;58&lt;tt&gt;
&lt;/tt&gt;59&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;60&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;61&lt;tt&gt;
&lt;/tt&gt;62&lt;tt&gt;
&lt;/tt&gt;63&lt;tt&gt;
&lt;/tt&gt;64&lt;tt&gt;
&lt;/tt&gt;65&lt;tt&gt;
&lt;/tt&gt;66&lt;tt&gt;
&lt;/tt&gt;67&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;openssl&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;net/smtp&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;co&quot;&gt;Net&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;SMTP&lt;/span&gt;.class_eval &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  private&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;do_start&lt;/span&gt;(helodomain, user, secret, authtype)&lt;tt&gt;
&lt;/tt&gt;    raise &lt;span class=&quot;co&quot;&gt;IOError&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;SMTP session already started&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@started&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    check_auth_args user, secret, authtype &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; user &lt;span class=&quot;r&quot;&gt;or&lt;/span&gt; secret&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;    sock = timeout(&lt;span class=&quot;iv&quot;&gt;@open_timeout&lt;/span&gt;) { &lt;span class=&quot;co&quot;&gt;TCPSocket&lt;/span&gt;.open(&lt;span class=&quot;iv&quot;&gt;@address&lt;/span&gt;, &lt;span class=&quot;iv&quot;&gt;@port&lt;/span&gt;) }&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;iv&quot;&gt;@socket&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;Net&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;InternetMessageIO&lt;/span&gt;.new(sock)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;iv&quot;&gt;@socket&lt;/span&gt;.read_timeout = &lt;span class=&quot;i&quot;&gt;60&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;#@read_timeout&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;c&quot;&gt;#@socket.debug_output = STDERR #@debug_output&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;    check_response(critical { recv_response() })&lt;tt&gt;
&lt;/tt&gt;    do_helo(helodomain)&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; starttls&lt;tt&gt;
&lt;/tt&gt;      raise &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;openssl library not installed&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;defined?&lt;/span&gt;(&lt;span class=&quot;co&quot;&gt;OpenSSL&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;      ssl = &lt;span class=&quot;co&quot;&gt;OpenSSL&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;SSL&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;SSLSocket&lt;/span&gt;.new(sock)&lt;tt&gt;
&lt;/tt&gt;      ssl.sync_close = &lt;span class=&quot;pc&quot;&gt;true&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      ssl.connect&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@socket&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;Net&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;InternetMessageIO&lt;/span&gt;.new(ssl)&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@socket&lt;/span&gt;.read_timeout = &lt;span class=&quot;i&quot;&gt;60&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;#@read_timeout&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;c&quot;&gt;#@socket.debug_output = STDERR #@debug_output&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      do_helo(helodomain)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;    authenticate user, secret, authtype &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; user&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;iv&quot;&gt;@started&lt;/span&gt; = &lt;span class=&quot;pc&quot;&gt;true&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;ensure&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;unless&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@started&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;c&quot;&gt;# authentication failed, cancel connection.&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@socket&lt;/span&gt;.close &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@started&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@socket&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@socket&lt;/span&gt;.closed?&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;iv&quot;&gt;@socket&lt;/span&gt; = &lt;span class=&quot;pc&quot;&gt;nil&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;do_helo&lt;/span&gt;(helodomain)&lt;tt&gt;
&lt;/tt&gt;     &lt;span class=&quot;r&quot;&gt;begin&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@esmtp&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        ehlo helodomain&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;else&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        helo helodomain&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;co&quot;&gt;Net&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;ProtocolError&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;iv&quot;&gt;@esmtp&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;iv&quot;&gt;@esmtp&lt;/span&gt; = &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;iv&quot;&gt;@error_occured&lt;/span&gt; = &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;r&quot;&gt;retry&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      raise&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;starttls&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    getok(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;STARTTLS&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;) &lt;span class=&quot;r&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;true&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;quit&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;begin&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      getok(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;QUIT&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;co&quot;&gt;EOFError&lt;/span&gt;, &lt;span class=&quot;co&quot;&gt;OpenSSL&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;SSL&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;SSLError&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


Then, add these at the bottom of &lt;span class=&quot;caps&quot;&gt;RAILS&lt;/span&gt;_ROOT/config/environments/development.rb
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;co&quot;&gt;ActionMailer&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;.server_settings = {&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;sy&quot;&gt;:address&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;smtp.gmail.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;sy&quot;&gt;:port&lt;/span&gt; =&amp;gt; &lt;span class=&quot;i&quot;&gt;587&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;sy&quot;&gt;:domain&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;mycompany.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;sy&quot;&gt;:authentication&lt;/span&gt; =&amp;gt; &lt;span class=&quot;sy&quot;&gt;:plain&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;sy&quot;&gt;:user_name&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;sy&quot;&gt;:password&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;}&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;Add your username and password, restart the server and you&#8217;re good to go. Note that the emails your app sends might end up in the bulk folder.&lt;/p&gt;


	&lt;p&gt;Link
&lt;a href=&quot;http://www.stephenchu.com/2006/06/how-to-use-gmail-smtp-server-to-send.html&quot;&gt;How to use GMail &lt;span class=&quot;caps&quot;&gt;SMTP&lt;/span&gt; server to send emails in Rails ActionMailer&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-07-22:10</id>
    <published>2007-07-22T03:01:00Z</published>
    <updated>2007-07-22T03:05:18Z</updated>
    <link href="http://topher.88-mph.net/2007/7/22/capistrano-2-0" rel="alternate" type="text/html"/>
    <title>Capistrano 2.0</title>
<content type="html">
            &lt;p&gt;Capistrano 2.0 is out. Check the announcement &lt;a href=&quot;http://weblog.rubyonrails.com/2007/7/22/capistrano-2-0&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Capistrano is great for automating tasks via &lt;span class=&quot;caps&quot;&gt;SSH&lt;/span&gt; on remote servers, like software installation, application deployment, configuration management, ad hoc server monitoring, and more.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;Learn more about capistrano on it&#8217;s &lt;a href=&quot;http://www.capify.org&quot;&gt;website&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;I like to share my deployment recipe. After running &#8220;capify .&#8221; on the app directory, I got the file config/deploy.rb. Initially it looks like this&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;set &lt;span class=&quot;sy&quot;&gt;:application&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;set your application name here&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;set &lt;span class=&quot;sy&quot;&gt;:repository&lt;/span&gt;,  &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;set your repository location here&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# If you aren't deploying to /u/apps/#{application} on the target&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# servers (which is the default), you can specify the actual location&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# via the :deploy_to variable:&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# set :deploy_to, &amp;quot;/var/www/#{application}&amp;quot; &lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# If you aren't using Subversion to manage your source code, specify&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# your SCM below:&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# set :scm, :subversion&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;role &lt;span class=&quot;sy&quot;&gt;:app&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;your app-server here&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;role &lt;span class=&quot;sy&quot;&gt;:web&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;your web-server here&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;role &lt;span class=&quot;sy&quot;&gt;:db&lt;/span&gt;,  &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;your db-server here&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:primary&lt;/span&gt; =&amp;gt; &lt;span class=&quot;pc&quot;&gt;true&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;After putting in the values and adding some tasks, my deploy.rb looks like this&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;25&lt;tt&gt;
&lt;/tt&gt;26&lt;tt&gt;
&lt;/tt&gt;27&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;set &lt;span class=&quot;sy&quot;&gt;:application&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;topsecret&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;set &lt;span class=&quot;sy&quot;&gt;:repository&lt;/span&gt;,  &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;http://svn.example.com/topsecret/trunk&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# If you aren't deploying to /u/apps/#{application} on the target&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# servers (which is the default), you can specify the actual location&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;c&quot;&gt;# via the :deploy_to variable:&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;set &lt;span class=&quot;sy&quot;&gt;:deploy_to&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/home/topher/apps/&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;application&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;role &lt;span class=&quot;sy&quot;&gt;:app&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;topher.88-mph.net&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;role &lt;span class=&quot;sy&quot;&gt;:web&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;topher.88-mph.net&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;role &lt;span class=&quot;sy&quot;&gt;:db&lt;/span&gt;,  &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;topher.88-mph.net&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:primary&lt;/span&gt; =&amp;gt; &lt;span class=&quot;pc&quot;&gt;true&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;set &lt;span class=&quot;sy&quot;&gt;:mongrel_config&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/etc/mongrel_cluster/&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;application&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;.yml&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;namespace &lt;span class=&quot;sy&quot;&gt;:deploy&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  desc &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Link in the *.yml files and rails.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  task &lt;span class=&quot;sy&quot;&gt;:after_update_code&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    run &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;ln -nfs &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;deploy_to&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/shared/config/database.yml &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;release_path&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/config/database.yml&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;    run &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;ln -nfs &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;deploy_to&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/shared/config/mongrel_cluster.yml &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;release_path&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/config/mongrel_cluster.yml&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;    run &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;ln -nfs /home/topher/rails_src/rails_1_2_stable &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;release_path&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/vendor/rails&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  desc &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Restart the mongrels.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  task &lt;span class=&quot;sy&quot;&gt;:restart&lt;/span&gt; &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    sudo &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;mongrel_rails cluster::restart -C &lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;dl&quot;&gt;#{&lt;/span&gt;mongrel_config&lt;span class=&quot;dl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;ul&gt;
	&lt;li&gt;:application is the app name&lt;/li&gt;
		&lt;li&gt;:repository is the svn repository&lt;/li&gt;
		&lt;li&gt;:deploy_to is the path to the app in the server&lt;/li&gt;
		&lt;li&gt;roles :app, :web, and :db is the server. I&#8217;m using one server for the app, web, and db so they&#8217;re all the same.&lt;/li&gt;
		&lt;li&gt;:mongrel_config is config file to be used by the mongrel_cluster gem&lt;/li&gt;
		&lt;li&gt;I create symlinks to config/database.yml and config/mongrel_cluster.yml.&lt;/li&gt;
		&lt;li&gt;I use rails 1.2.3 for this app but the server has 1.1.6 installed. You can check in vendor/rails to svn (or svn externals) but I decided to put rails to a directory outside of the app so it can be shared by multiple apps. I just create a symlink.&lt;/li&gt;
		&lt;li&gt;I restart my mongrel cluster using the cluster::restart. The mongrel_cluster gem includes a recipe but so far it only works with capistrano 1.4. (Thanks to &lt;a href=&quot;http://nubyonrails.com/articles/tips-for-upgrading-to-capistrano-2&quot;&gt;topfunky&lt;/a&gt; for this.)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;To deploy I just run &#8220;cap deploy&#8221; on my development machine. To deploy with migrations run &#8220;cap deploy:migrations&#8221;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-07-19:9</id>
    <published>2007-07-19T02:41:00Z</published>
    <updated>2007-07-19T02:42:22Z</updated>
    <category term="Rails"/>
    <link href="http://topher.88-mph.net/2007/7/19/plugin-attachment_fu" rel="alternate" type="text/html"/>
    <title>Plugin: attachment_fu</title>
<content type="html">
            attachment_fu is a rails plugin written by &lt;a href=&quot;http://techno-weenie.net/&quot;&gt;Rick Olson&lt;/a&gt;. From the &lt;a href=&quot;http://svn.techno-weenie.net/projects/plugins/attachment_fu/README&quot;&gt;&lt;span class=&quot;caps&quot;&gt;README&lt;/span&gt;&lt;/a&gt;, 
	&lt;blockquote&gt;
		&lt;p&gt;attachment_fu facilitates file uploads in Ruby on Rails.  There are a few storage options for the actual file data, but the plugin always at a minimum stores metadata for each file in the database.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;Check out &lt;a href=&quot;http://clarkware.com/cgi/blosxom/2007/02/24&quot;&gt;Mike Clark&#8217;s tutorial&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;On windows, when I submit the form with the file upload, I get an error &#8220;Size not included in list&#8221;. Upon inspection, the size is zero. (The default minimum size is 1 byte.) The size of the file uploaded isn&#8217;t set properly. I found somewhere on the &lt;a href=&quot;http://beast.caboo.se/&quot;&gt;beast forum&lt;/a&gt; that you need to add &#8220;sleep 1&#8221; on your controller. I haven&#8217;t tried to use attachment_fu on my server (ubuntu) and I&#8217;m hoping this is only a problem with windows.&lt;/p&gt;


	&lt;p&gt;My friend Mon, also a rails developer, encountered another problem with attachment_fu. He added a user_id in the model which uses attachment_fu. When he saves the uploaded file, he gets an error saying that user_id is null. We&#8217;re absolutely sure there&#8217;s a user_id.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s what happened: attachment_fu can create a thumbnail(s) for you when you save the uploaded image (you will need an image processor like image magick). If you don&#8217;t specify a thumbnail_class, attachment_fu will use the same model for the thumbnail. So if you have a Mugshot model, after submitting the form, 1 model will be created for the uploaded image, and another one will be created for the thumbnail. So even if you add user_id to your model, the thumbnail won&#8217;t have a user_id. You need to add a callback before_thumbnail_saved on your model.&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;before_thumbnail_saved &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |record, thumbnail|&lt;tt&gt;
&lt;/tt&gt;  thumbnail.user_id = record.user_id&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;Install the plugin with&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-07-13:8</id>
    <published>2007-07-13T11:30:00Z</published>
    <updated>2007-07-13T11:30:29Z</updated>
    <category term="Rails"/>
    <link href="http://topher.88-mph.net/2007/7/13/editing-models-in-migrations" rel="alternate" type="text/html"/>
    <title>Editing models in migrations</title>
<content type="html">
            &lt;p&gt;In migrations, you can also edit your models. I have a Topic and a Post. A topic has many posts. The models are already created using previous migrations. Now I want to add 3 new fields to Topic&#8212;posts_count, replied_by, and replied_at.&lt;/p&gt;


	&lt;p&gt;Here is the migration:&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;16&lt;tt&gt;
&lt;/tt&gt;17&lt;tt&gt;
&lt;/tt&gt;18&lt;tt&gt;
&lt;/tt&gt;19&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;20&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;21&lt;tt&gt;
&lt;/tt&gt;22&lt;tt&gt;
&lt;/tt&gt;23&lt;tt&gt;
&lt;/tt&gt;24&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;AddCachedFieldsOnTopic&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Migration&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;Topic&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    has_many &lt;span class=&quot;sy&quot;&gt;:posts&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:order&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;posts.created_at&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;cl&quot;&gt;Post&lt;/span&gt; &amp;lt; &lt;span class=&quot;co&quot;&gt;ActiveRecord&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;; &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.up&lt;tt&gt;
&lt;/tt&gt;    add_column &lt;span class=&quot;sy&quot;&gt;:topics&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:posts_count&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:integer&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:default&lt;/span&gt; =&amp;gt; &lt;span class=&quot;i&quot;&gt;0&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    add_column &lt;span class=&quot;sy&quot;&gt;:topics&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:replied_by&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:integer&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    add_column &lt;span class=&quot;sy&quot;&gt;:topics&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:replied_at&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:datetime&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;co&quot;&gt;Topic&lt;/span&gt;.find(&lt;span class=&quot;sy&quot;&gt;:all&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:include&lt;/span&gt; =&amp;gt; &lt;span class=&quot;sy&quot;&gt;:posts&lt;/span&gt;).each &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |topic|&lt;tt&gt;
&lt;/tt&gt;      last_post = topic.posts.last&lt;tt&gt;
&lt;/tt&gt;      posts_count = topic.posts.size&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;co&quot;&gt;Topic&lt;/span&gt;.update_all([&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;posts_count = ?, replied_by = ?, replied_at = ?&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, posts_count, last_post.user_id, last_post.created_at], [&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;id = ?&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, topic.id]) &lt;span class=&quot;r&quot;&gt;if&lt;/span&gt; last_post&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;pc&quot;&gt;self&lt;/span&gt;.down&lt;tt&gt;
&lt;/tt&gt;    remove_column &lt;span class=&quot;sy&quot;&gt;:topics&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:posts_count&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    remove_column &lt;span class=&quot;sy&quot;&gt;:topics&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:replied_by&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    remove_column &lt;span class=&quot;sy&quot;&gt;:topics&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:replied_at&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


Notes
	&lt;ul&gt;
	&lt;li&gt;posts_count will be used by rails for caching. In the post model, I&#8217;ll put :belongs_to :topic, :counter_cache =&amp;gt; true. Set the default to 0.&lt;/li&gt;
		&lt;li&gt;You can actually get these fields through the association&#8212;topic.posts.count, topic.posts.last.user, topic.posts.last.created_at &#8211; but I&#8217;m adding it to Topic to avoid the additional queries.&lt;/li&gt;
		&lt;li&gt;I&#8217;m looking at (copying) the beast application.&lt;/li&gt;
	&lt;/ul&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-07-05:7</id>
    <published>2007-07-05T14:06:00Z</published>
    <updated>2007-07-15T02:49:11Z</updated>
    <category term="Rails"/>
    <link href="http://topher.88-mph.net/2007/7/5/server-setup" rel="alternate" type="text/html"/>
    <title>Server Setup</title>
<content type="html">
            &lt;p&gt;I have a &lt;span class=&quot;caps&quot;&gt;VPS&lt;/span&gt; from &lt;a href=&quot;http://rimuhosting.com&quot;&gt;Rimuhosting&lt;/a&gt; and I&#8217;m using &lt;a href=&quot;http://nginx.net/&quot;&gt;nginx&lt;/a&gt; and a cluster of &lt;a href=&quot;http://mongrel.rubyforge.org/&quot;&gt;mongrel&lt;/a&gt; for my rails applications. I followed this &lt;a href=&quot;http://kyledev.blogspot.com/2006/11/setting-up-secure-and-complete-ruby.html&quot;&gt;tutorial&lt;/a&gt; which guides you on setting up everything &#8211; ruby, rails, nginx, mongrel, postgresql, subversion and capistrano. I&#8217;m sharing my vps with some friends and ruby, rails, and mysql were already installed. I&#8217;m using Dreamhost for subversion. Setting up nginx and mongrel is easy. I just followed the tutorial and didn&#8217;t encounter any problem.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Mongrel is a fast &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; library and server for Ruby that is intended for hosting Ruby web applications of any kind using plain &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; rather than FastCGI or &lt;span class=&quot;caps&quot;&gt;SCGI&lt;/span&gt;. It is framework agnostic and already supports Ruby On Rails, Og+Nitro, Camping, and &lt;span class=&quot;caps&quot;&gt;IOWA&lt;/span&gt; frameworks.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;I use nginx for this reason (taken from the faq page in mongrel website):&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Ruby on Rails is not thread safe so there is a synchronized block around the calls to Dispatcher.dispatch. This means that everything is threaded right before and right after Rails runs. While Rails is running there is only one controller in operation at a time. This is why people typically have to run a small set of Mongrel processes (a “Pack of Mongrels”) to get good concurrency.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;For a rails application, I run 2 mongrel servers. I use the gem mongrel_cluster to manage these mongrels (this is in the tutorial). For example, mongrels are running in port 7500 and 7501. When a request is made, nginx passes that request to one of the mongrels. For bigger applications, use more mongrels.&lt;/p&gt;


	&lt;p&gt;Since I&#8217;m sharing the &lt;span class=&quot;caps&quot;&gt;VPS&lt;/span&gt; with my friends, I can&#8217;t change the web server easily. Besides, they are running php and though it&#8217;s possible to run php in nginx I haven&#8217;t researched that yet. We are using Apache 2.0 which is not easy to set up with mongrel. Apache 2.2 is recommended. I have to run nginx on a different port, say 8088. Then on the apache conf file, I put this&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;VirtualHost&lt;/span&gt; &lt;span class=&quot;er&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;an&quot;&gt;:80&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;        ServerName topher.88-mph.net&lt;tt&gt;
&lt;/tt&gt;        ServerAdmin crigor@gmail.com&lt;tt&gt;
&lt;/tt&gt;        ProxyRequests Off&lt;tt&gt;
&lt;/tt&gt;        ProxyPreserveHost on&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;ta&quot;&gt;&amp;lt;Location&lt;/span&gt; &lt;span class=&quot;ta&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;          ProxyPass http://topher.88-mph.net:8088/&lt;tt&gt;
&lt;/tt&gt;          ProxyPassReverse http://topher.88-mph.net:8088/&lt;tt&gt;
&lt;/tt&gt;        &lt;span class=&quot;ta&quot;&gt;&amp;lt;/Location&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/VirtualHost&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;When you go to topher.88-mph.net, apache gets the request then passes it to ngingx which in turns passes it to one of the mongrels. Apache is not really needed on this set up.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-06-21:5</id>
    <published>2007-06-21T12:00:00Z</published>
    <updated>2007-06-21T12:11:19Z</updated>
    <category term="Rails"/>
    <link href="http://topher.88-mph.net/2007/6/21/ruby-script-for-creating-a-rails-app" rel="alternate" type="text/html"/>
    <title>Ruby script for creating a rails app</title>
<content type="html">
            &lt;p&gt;A few months ago I saw this &lt;a href=&quot;http://webonrails.com/2007/02/08/ruby-script-for-creating-new-rails-project-and-initial-svn-import-with-ignoringremoving-logother-files/&quot;&gt;ruby script&lt;/a&gt;  by &lt;a href=&quot;http://webonrails.com&quot;&gt;Akhil Bansal&lt;/a&gt; which creates a rails app and imports it to svn, ignoring and removing files like database.yml, tmp directory and log files.&lt;/p&gt;


I modified it to use the trunk, tags, and branches directories and updated some of the code. Here&#8217;s what the script does:
	&lt;ul&gt;
	&lt;li&gt;create a rails app in your local machine&lt;/li&gt;
		&lt;li&gt;create trunk, tags and branches directories in the svn repository&lt;/li&gt;
		&lt;li&gt;svn import the rails app&lt;/li&gt;
		&lt;li&gt;delete the app in your local machine&lt;/li&gt;
		&lt;li&gt;check out from svn&lt;/li&gt;
		&lt;li&gt;remove log files from svn&lt;/li&gt;
		&lt;li&gt;ignore log files&lt;/li&gt;
		&lt;li&gt;ignore tmp directory&lt;/li&gt;
		&lt;li&gt;remove tmp directory from svn&lt;/li&gt;
		&lt;li&gt;move database.yml to database.yml.sample&lt;/li&gt;
		&lt;li&gt;ignore database.yml&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Download the script &lt;a href=&quot;http://topher.88-mph.net/assets/2007/6/21/create_rails_with_subversion.rb&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Run it with &#8220;ruby create_rails_with_subversion.rb&#8221; on the command line. You need svn installed on your local machine and a subversion repository.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-05-12:4</id>
    <published>2007-05-12T07:12:00Z</published>
    <updated>2007-05-12T07:12:23Z</updated>
    <category term="Django"/>
    <link href="http://topher.88-mph.net/2007/5/12/django-contrib-databrowse" rel="alternate" type="text/html"/>
    <title>django.contrib.databrowse</title>
<content type="html">
            &lt;p&gt;There&#8217;s a new django.contrib add-on called databrowse. From the &lt;a href=&quot;http://www.djangoproject.com/documentation/databrowse/&quot;&gt;documentaion&lt;/a&gt;,&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Databrowse is a Django application that lets you browse your data.
As the Django admin dynamically creates an admin interface by introspecting your models, Databrowse dynamically creates a rich, browsable Web site by introspecting your models.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;You need to:&lt;/p&gt;


	&lt;p&gt;1.  Add &#8216;django.contrib.databrowse&#8217; to your &lt;span class=&quot;caps&quot;&gt;INSTALLED&lt;/span&gt;_APPS setting.&lt;/p&gt;


	&lt;p&gt;You don&#8217;t need to run syncdb.&lt;/p&gt;


	&lt;p&gt;2. Register models on the Databrowse site.&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;from django.contrib import databrowse&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;databrowse.site.register(&lt;span class=&quot;co&quot;&gt;SomeModel&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;databrowse.site.register(&lt;span class=&quot;co&quot;&gt;SomeOtherModel&lt;/span&gt;)&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;You can put this on urls.py.&lt;/p&gt;


	&lt;p&gt;3. Add to your URLConf&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;(r&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;^databrowse/(.*)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, databrowse.site.root),&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;Test databroswe by going to /databrowse.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s a screenshot:
&lt;img src=&quot;http://topher.88-mph.net/assets/2007/5/12/databrowse-resized.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;a href=&quot;http://topher.88-mph.net/assets/2007/5/12/databrowse.JPG&quot;&gt;Full screen&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-04-27:3</id>
    <published>2007-04-27T14:03:00Z</published>
    <updated>2007-04-27T14:07:39Z</updated>
    <category term="Django"/>
    <link href="http://topher.88-mph.net/2007/4/27/using-named-url-patterns-in-django-views" rel="alternate" type="text/html"/>
    <title>Using named URL patterns in Django views</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.djangoproject.com/documentation/url_dispatch/#naming-url-patterns&quot;&gt;Named &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; patterns&lt;/a&gt; have been added to Django recently but the documentation isn&#8217;t complete yet.&lt;/p&gt;


	&lt;p&gt;In urls.py, use url()&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;urlpatterns = patterns(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;tt&gt;
&lt;/tt&gt;    url(r&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;^$&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, index, name=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;app_index&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;),&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;On the templates, use url()&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;a&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;href&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;{% url app_index %}&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;Home&lt;span class=&quot;ta&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;On the views, use django.core.urlresolvers.reverse()&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;from django.core.urlresolvers import reverse&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;some_method&lt;/span&gt;(request):&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;return&lt;/span&gt; HttpResponseRedirect(reverse(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;app_index&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;))&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
          </content>  </entry>
  <entry xml:base="http://topher.88-mph.net/">
    <author>
      <name>topher</name>
    </author>
    <id>tag:topher.88-mph.net,2007-04-26:2</id>
    <published>2007-04-26T13:54:00Z</published>
    <updated>2007-06-20T12:47:10Z</updated>
    <category term="Rails"/>
    <link href="http://topher.88-mph.net/2007/4/26/exporting-to-csv-in-rails" rel="alternate" type="text/html"/>
    <title>Exporting to CSV in Rails</title>
<content type="html">
            &lt;p&gt;To export data to &lt;span class=&quot;caps&quot;&gt;CSV&lt;/span&gt;, I use &lt;span class=&quot;caps&quot;&gt;CSV&lt;/span&gt;::Writer.&lt;/p&gt;


&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;report&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;co&quot;&gt;CSV&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Writer&lt;/span&gt;.generate(output=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |csv|&lt;tt&gt;
&lt;/tt&gt;    csv &amp;lt;&amp;lt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;%w(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Name Price&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;iv&quot;&gt;@items&lt;/span&gt;.each &lt;span class=&quot;r&quot;&gt;do&lt;/span&gt; |item|&lt;tt&gt;
&lt;/tt&gt;       csv &amp;lt;&amp;lt; [item.name, item.price]&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;  send_data(output,&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;sy&quot;&gt;:type&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;text/csv&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;sy&quot;&gt;:filename&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;report.csv&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;You can also checkout FasterCSV.&lt;/p&gt;
          </content>  </entry>
</feed>
