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

<channel>
	<title>Nuclear Rooster &#187; Ruby/Rails</title>
	<atom:link href="http://dev.nuclearrooster.com/category/rubyrails/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.nuclearrooster.com</link>
	<description></description>
	<lastBuildDate>Mon, 19 Jul 2010 03:48:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Installing mysql gem on RHEL 5.2 Tikanga.  This actually works.</title>
		<link>http://dev.nuclearrooster.com/2009/04/27/installing-mysql-gem-on-rhel-52-tikanga-this-actually-works/</link>
		<comments>http://dev.nuclearrooster.com/2009/04/27/installing-mysql-gem-on-rhel-52-tikanga-this-actually-works/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 18:54:51 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[linux / os x]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[RHEL]]></category>
		<category><![CDATA[RHEL 5]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=96</guid>
		<description><![CDATA[Ok, lets start at the beginning. Nice, freshish RHEL 5.2 box. Try to install mysql gem... [nick@Dev1 ~]$ sudo gem install mysql Password: Building native extensions. This could take a while... ERROR: Error installing mysql: ERROR: Failed to build gem native extension. /usr/bin/ruby extconf.rb checking for mysql_query() in -lmysqlclient... no checking for main() in -lm... [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, lets start at the beginning.  Nice, freshish RHEL 5.2 box.  Try to install mysql gem...</p>
<pre class="brush: bash;">
[nick@Dev1 ~]$ sudo gem install mysql
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
	ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/usr/bin/ruby
	--with-mysql-config
	--without-mysql-config
	--with-mysql-dir
	--without-mysql-dir
	--with-mysql-include
	--without-mysql-include=${mysql-dir}/include
	--with-mysql-lib
	--without-mysql-lib=${mysql-dir}/lib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-mlib
	--without-mlib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-zlib
	--without-zlib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-socketlib
	--without-socketlib
	--with-mysqlclientlib
	--without-mysqlclientlib
	--with-nsllib
	--without-nsllib
	--with-mysqlclientlib
	--without-mysqlclientlib

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
</pre>
<p>Yikes! Look familiar? Bummer.  First step, brute force install everything I could think might be missing</p>
<pre class="brush: bash;">
sudo yum install gcc mysql-server mysql-devel ruby ruby-devel
</pre>
<p>Turns  out, the gcc was having some issues:</p>
<pre class="brush: bash;">
[nick@Dev1 mysql-2.7]$ sudo yum install gcc
Loading &quot;rhnplugin&quot; plugin
Loading &quot;security&quot; plugin
intensive-rhel-i386-serve 100% |=========================| 1.2 kB    00:00
rackspace-int-rhel-i386-s 100% |=========================| 1.2 kB    00:00
Excluding Packages in global exclude list
Finished
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--&gt; Running transaction check
---&gt; Package gcc.i386 0:4.1.2-42.el5 set to be updated
--&gt; Processing Dependency: libgomp = 4.1.2-42.el5 for package: gcc
--&gt; Processing Dependency: cpp = 4.1.2-42.el5 for package: gcc
--&gt; Processing Dependency: libgomp.so.1 for package: gcc
--&gt; Processing Dependency: glibc-devel &gt;= 2.2.90-12 for package: gcc
--&gt; Running transaction check
---&gt; Package cpp.i386 0:4.1.2-42.el5 set to be updated
---&gt; Package glibc-devel.i386 0:2.5-24.el5_2.2 set to be updated
--&gt; Processing Dependency: glibc-headers = 2.5-24.el5_2.2 for package: glibc-devel
--&gt; Processing Dependency: glibc-headers for package: glibc-devel
---&gt; Package libgomp.i386 0:4.1.2-42.el5 set to be updated
--&gt; Running transaction check
---&gt; Package glibc-headers.i386 0:2.5-24.el5_2.2 set to be updated
--&gt; Processing Dependency: kernel-headers &gt;= 2.2.1 for package: glibc-headers
--&gt; Processing Dependency: kernel-headers for package: glibc-headers
--&gt; Finished Dependency Resolution
Error: Missing Dependency: kernel-headers is needed by package glibc-headers
Error: Missing Dependency: kernel-headers &gt;= 2.2.1 is needed by package glibc-headers
</pre>
<p>Googling around a little, I found <a href="http://episteme.arstechnica.com/eve/forums/a/tpc/f/96509133/m/197006069831/inc/1">this helpful page</a>  which indicated that the default RHEL yum configuration excludes updates from the kernel.  That is probably good practice in general, but right now it is preventing us from doing what "needs to be done." </p>
<p>Looking at my /etc/yum.conf file, indeed the kernal was excepted from updates:</p>
<pre class="brush: bash;">
[nick@Dev1 ~]$ cat /etc/yum.conf
[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1

# Note: yum-RHN-plugin doesn't honor this.
metadata_expire=1h

# Default.
# installonly_limit = 3

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
exclude=kernel*
</pre>
<p>So I commented out that line, yum installed gcc, and then off to the races.  My googling also noted that passing the --with-mysql-config saves you some trouble, essentially letting it configure itself.</p>
<pre class="brush: bash;">

[nick@Dev1 ~]$ sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
Building native extensions.  This could take a while...
Successfully installed mysql-2.7
1 gem installed
</pre>
<p>Just in case, you might want to uncomment the kernal extension from your /etc/yum.conf file!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2009/04/27/installing-mysql-gem-on-rhel-52-tikanga-this-actually-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Errno::EACCES permissions error using paperclip with JRuby on Joyent</title>
		<link>http://dev.nuclearrooster.com/2009/03/03/errnoeacces-permissions-error-using-paperclip/</link>
		<comments>http://dev.nuclearrooster.com/2009/03/03/errnoeacces-permissions-error-using-paperclip/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 20:32:41 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[Joyent Accelerator]]></category>
		<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[joyent]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=85</guid>
		<description><![CDATA[We ran into a permission error using the 'paperclip' plugin. It had something to do with moving a tmp file into the rails public directory. The odd thing was that it could create the appropriate directories in the rails public directory, but it couldn't copy the file. Digging around the web, I found this group [...]]]></description>
			<content:encoded><![CDATA[<p>We ran into a permission error using the 'paperclip' plugin.  It had something to do with moving a tmp file into the rails public directory.  The odd thing was that it could create the appropriate directories in the rails public directory, but it couldn't copy the file.</p>
<p>Digging around the web, I found this group about this exact problem. </p>
<p>http://groups.google.com/group/paperclip-plugin/browse_thread/thread/4a0a97a08929d3a5</p>
<p> I found that I had all of the patches, but it still didn't work.  Most of the people on the group were complaining it that it didn't work on Windows, and maybe had something to do with file handles, etc.  We were trying to get this working in JRuby on a Joyent Solaris Accelerator, each of which can make things a little different than a MRI Rails app on Linux.</p>
<p>Following a tip from a user on the group, simply changing the way the move happens fixes this problem.  I would like to fix the root cause, but I got it working for me, and (*open source sigh*) don't want to isolate the exact problem.</p>
<blockquote><p>
After that, i made some change in storage.rb#flush_writes.<br />
It's a short workaround for</p>
<pre class="brush: ruby;">
  FileUtils.mv
</pre>
<p>Simply replace it with</p>
<pre class="brush: ruby;">
  FileUtils.cp(file.path, path(style))
  FileUtils.rm(file.path)
</pre>
<p>Currently, it works for me. But please consider, it isn't checked against a well written test or any other platform.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2009/03/03/errnoeacces-permissions-error-using-paperclip/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rake task with arguments</title>
		<link>http://dev.nuclearrooster.com/2009/01/05/rake-task-with-arguments/</link>
		<comments>http://dev.nuclearrooster.com/2009/01/05/rake-task-with-arguments/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 01:26:43 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[OS X]]></category>
		<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux / os x]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=75</guid>
		<description><![CDATA[I couldn't find a short, concise example of a rake task with arguments, so I decided to write one up for the world to see. Firstly, the ability to add arguments was added somewhere along the line, so you might as well make sure you have a recent version of Rake: nicks-computer:~ nick$ sudo gem [...]]]></description>
			<content:encoded><![CDATA[<p>I couldn't find a short, concise example of a rake task with arguments, so I decided to write one up for the world to see.  </p>
<p>Firstly, the ability to add arguments was added somewhere along the line, so you might as well make sure you have a recent version of Rake:</p>
<pre class="brush: plain;">
nicks-computer:~ nick$ sudo gem install rake
Password:
Successfully installed rake-0.8.3
1 gem installed
Installing ri documentation for rake-0.8.3...
Installing RDoc documentation for rake-0.8.3...
</pre>
<p>Great.  Now, lets dig in to an example rake file.  You can put this in a file name 'Rakefile' anywhere you like, or in RAILS_ROOT/lib/tasks/some_file.rake if you are rails-ish.</p>
<pre class="brush: ruby;">
desc &quot;An example task that uses a single argument&quot;
task :example_with_argument, :arg1 do |t, args|
  puts &quot;Running 'example_with_argument' with '#{args.arg1}' as the argument&quot;
end

desc &quot;An example task that uses multiple arguments&quot;
task :example_with_multiple_arguments, :arg1, :arg2 do |t, args|
  puts &quot;Running 'example_with_argument' with '#{args.arg1}' and '#{args.arg2}' as the arguments&quot;
end

desc &quot;An example task that uses multiple arguments, and has defaults&quot;
task :example_with_multiple_arguments_and_defaults, :arg1, :arg2 do |t, args|
  args.with_defaults(:arg1 =&gt; 'default_arg1', :arg2 =&gt; 'default_arg2')
  puts &quot;Running 'example_with_argument' with '#{args.arg1}' and '#{args.arg2}' as the arguments&quot;
end
</pre>
<p>Now, for how to run them.  Without specifying arguments, the defaults (or an empty string if no defaults are specified) will be used:</p>
<pre class="brush: plain;">
nicks-computer:~ nick$ rake example_with_multiple_arguments_and_defaults
(in /Users/nick)
Running 'example_with_argument' with 'default_arg1' and 'default_arg2' as the arguments
</pre>
<pre class="brush: plain;">
nicks-computer:~ nick$ rake example_with_multiple_arguments_and_defaults[myarg1, myarg2]
(in /Users/nick)
Running 'example_with_argument' with 'myarg1' and 'myarg2' as the arguments
</pre>
<p>TaDa!</p>
<p>UPDATE:</p>
<p>Rake a a great tool, and widely used, but there are some new tools that surpass rake in some areas.  For example check out <a href="http://yehudakatz.com/2008/05/12/by-thors-hammer/">Thor</a> and how <a href="http://www.opscode.com/">OpsCode<a/> uses it with their <a href="http://wiki.opscode.com/display/chef/Knife">Knife</a> tool.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2009/01/05/rake-task-with-arguments/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple Rails Uploader</title>
		<link>http://dev.nuclearrooster.com/2008/04/10/simple-rails-uploader/</link>
		<comments>http://dev.nuclearrooster.com/2008/04/10/simple-rails-uploader/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 16:26:27 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[stupid tricks]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=34</guid>
		<description><![CDATA[Simple Rails Uploader I was recently trying to implement an upload to Amazon S3, and it wasn't working. I couldn't tell if it was the Flex front end, or the S3 backend, or what, so I decided to Wear my ruby slippers to work, or rather my Rails slippers (so comfy and I just like [...]]]></description>
			<content:encoded><![CDATA[<h3>Simple Rails Uploader</h3>
<p>I was recently <a href="http://dev.nuclearrooster.com/2008/04/05/uploading-with-a-filereference-from-flex-3-on-os-x/">trying to implement an upload </a>to Amazon S3, and it wasn't working.  I couldn't tell if it was the Flex front end, or the S3 backend, or what, so I decided to <a href="http://whytheluckystiff.net/articles/wearingRubySlippersToWork.html">Wear my ruby slippers to work</a>, or rather my Rails slippers (so comfy and I just like them so much).</p>
<p>About 15 minutes and 15 lines of code later, I had a rails app running locally which accepted the upload from Flex and logged all the request parameters. I found the <a href="http://manuals.rubyonrails.com/read/chapter/77">Simplest upload that could possibly work</a> in the Rails Cookbook, and a <a href="http://wiki.rubyonrails.org/rails/pages/HowtoUploadFiles">Rails wiki page</a> to that purpose.  In the Rails Cookbook, note that you should use <code>params['file']</code> rather than the oldschool <code>@params['file']</code>.</p>
<p>To get a simple Rails (> 2.0) app for testing the uploads, try this</p>
<pre>
rails uploader
cd uploader
script/generate controller upload
</pre>
<p>Paste in some code from the Simplest Upload Possible article above.</p>
<pre class="brush: ruby;">
class UploadController &lt; ApplicationController
  def save_file
    logger.info(params.insect)

    if request.get?
    render :text =&gt; 'Please Upoad file'
    else
      # Use &quot;wb&quot; mode on windows.
      File.open(&quot;#{RAILS_ROOT}/public/files/#{Time.now.to_i}.jpg&quot;, &quot;w&quot;) do |f|
        f.write(params['file'].read)
      end
    render :text =&gt; 'Done'
    end
  end
end
</pre>
<p>Now, in Flex, have your FileReference upload to your server, and make sure to use the right field name.</p>
<p>[ActionScript]<br />
var urlRequest:URLRequest = new URLRequest("http://127.0.0.1:3000/upload/save_file");<br />
urlRequest.method = URLRequestMethod.POST;<br />
file.upload(urlRequest, "file");<br />
[/ActionScript]</p>
<p>Tails your logs, and look for the output.  One step closer.</p>
<p>I might try to clean up a simple uploader app and thow it up (blaagh) here.  Any interest?</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2008/04/10/simple-rails-uploader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uploading to S3 with a FileReference from Flex 3 on OS X</title>
		<link>http://dev.nuclearrooster.com/2008/04/05/uploading-with-a-filereference-from-flex-3-on-os-x/</link>
		<comments>http://dev.nuclearrooster.com/2008/04/05/uploading-with-a-filereference-from-flex-3-on-os-x/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 19:23:14 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Ruby/Rails]]></category>
		<category><![CDATA[Amazon S3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=33</guid>
		<description><![CDATA[After working on a fairly simple upload from Flex to Amazon S3, a co-worker claimed it was "done". Ok. Then I tried uploading from from my mac. No dice. So this simple upload went from being "done" to "a significant OS X pain." Here are some of the things that helped. After much googling, Wiresharking, [...]]]></description>
			<content:encoded><![CDATA[<p>After working on a fairly simple upload from Flex to Amazon S3, a co-worker claimed it was "done". Ok.  Then I tried uploading from from my mac.  No dice. So this simple upload went from being "done" to "a significant OS X pain."  Here are some of the things that helped.</p>
<p>After much googling, Wiresharking, and general debuggation, a co-worker found <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/HTTPPOSTFlash.html">this Amazon S3 doc</a>, which notes:</p>
<blockquote><p>
Some versions of the Adobe Flash Player do not properly handle HTTP responses that have an empty body. To configure POST to return a response that does not have an empty body, set success_action_status to 201. When set, Amazon S3 returns an XML document with a 201 status code. For information on the content of the XML document, see ???. For information on form fields, see HTML Form Fields.
</p></blockquote>
<p>Interesting. And small; it is a tiny message, almost a footnote, on some Amazon page. I wish Adobe could get their docs together.  I particularly like "Some versions" and "???".  Anyway, lesson learned, or at least we have something to try.</p>
<h3>The S3/Flash interactions need a little massaging</h3>
<p>It seems like the OS X Flash runtime (9.0.115.0) requires a non-empty server response from its POST.  Amazon S3 conveniently has an additional parameter, <code>success_action_status</code> which can be set to "201" to have S3 respond to the post with a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">201 CREATED response code</a>.  If you are uploading to Apache or IIS, you could have the same problem.  Try to check the header response for your POST, and see it is is a) empty, or b) not a 201.</p>
<p>On S3, you can modify your upload policy to return the correct response.  Your policy should look something like this:</p>
<pre>
{
    'expiration': '2008-12-31T12:00:00.000Z',
    'conditions': [
        {'bucket': 'my_test_bucket'},
        {'key': 'test1.jpg'},
        ['starts-with', '$Filename', ''],
        ['eq', '$success_action_status', '201']
    ]
}
</pre>
<p>Note that the <code>success_action_status</code> is not an object property, but an [Operator, Operand, Operand] array.</p>
<p>Problem Solved?  Not quite: still not uploads.</p>
<h3>S3 Upload Example</h3>
<p>Someone at AWS posted a helpful <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1092">Flex -> S3 example</a>, or actually examples.  One Flex project creates and signs a policy, and the other uploads a file using the generated policy.  And whats more, they both work.  Also, took a look at the code to make sure it wasn't sending my AWS key/password off to some email! Ha. I think it was also posted by an AWS employee, so that is reassuring.</p>
<h3>#2038 FileIOError </h3>
<p>I kept getting a #2038 FileIOError on my mac.  Bummer. Taking a closer look at the working AWS example, I saw a funny comment.  Not funny roflcopter, but funny smelly bug-fixy.</p>
<pre>

            /*
             * FileReference.upload likes to send cryptic IOErrors when it doesn't get a status code that it likes.
             * If we already got an error HTTP status code, don't propagate this event since the HTTPStatusEvent
             * event handler dispatches an IOErrorEvent.
             */
</pre>
<p>As it turns out, I could NOT stop these #2038 FIleIOErrors.  They just kept coming. But, as the example code reminded me, if you are getting a successful server response, the file is already up there.  Sure enough, the file was there.</p>
<p>So you can pretty much ignore the FileIOError, although you should handle it, and just ignore it if you have a successful HTTP response, something like this:</p>
<pre>
        private function onIOError(event:IOErrorEvent):void
        {
            if(!recievedSuccessfulHTTPresponse)
            {
                this.dispatchEvent(event);
            }
        }
</pre>
<p>You get the idea.  Ok. Handle but ignore FileIOErrors. Done? Almost. Single uploads work, but I get an  "Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error" when doing multiple uploads, via a FileReferenceList.  Marvelous.  This turned out to be even more of a pain.  It wasn't anything to do with <a href="http://www.judahfrangipane.com/blog/?p=115">the server side upload script</a> as my google searches might have me believe.</p>
<p>After brainstorming with a co-worker, we came to a pretty good guess: Garbage Collection.  Maybe the FileReference was going out of scope before the IOError could be handled, or some such.  PC/OS X differences in the runtime could have different GC implementations.  Worth a shot.  I changed my event listeners from "weak" to "strong" references.  Shahooya.  Multiple file upload city. </p>
<h3>Other fixes</h3>
<p>Make sure you have a publicly accessable crossdomain policy on the server you are uploading to.</p>
<p>Also, S3 scales well but adds extra complexity. You might try uploading to somewhere else, like a simple rails uploader.</p>
<p>Hope that helps.  Also, please comment.  In fact, today only, every commenter gets a free XBox.  You know, its just a little lonely out here in the cloud sometimes.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2008/04/05/uploading-with-a-filereference-from-flex-3-on-os-x/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Creating a Ruby Gem for SMTP_TLS</title>
		<link>http://dev.nuclearrooster.com/2007/12/12/creating-a-ruby-gem-for-smtp_tls/</link>
		<comments>http://dev.nuclearrooster.com/2007/12/12/creating-a-ruby-gem-for-smtp_tls/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 00:19:13 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[Ruby/Rails]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=24</guid>
		<description><![CDATA[UPDATE (1/12/10) Since this is remarkably one of my most popular posts, I feel compelled to point you towards this Ruby Inside article that will probably help you out a lot more than this post. As you may know, the Ruby 1.8.* Net::SMTP library does not allow for TLS (SSL) connections. This prevents you from [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><em>UPDATE (1/12/10)</em><br />
Since this is remarkably one of my most popular posts, I feel compelled to point you towards <a href="http://www.rubyinside.com/ruby-email-library-2782.html">this Ruby Inside article</a> that will probably help you out a lot more than  this post.</p></blockquote>
<p>As you may know, the Ruby 1.8.* Net::SMTP library does not allow for TLS (SSL) connections. This prevents you from connecting to Gmail, or other mail servers that require a secure connection.  Fortunatly, there is a pretty tight bit of code to fix this problem.  As far as I can tell, this code originated at a <a href="http://d.hatena.ne.jp/zorio/20060416">japanese site</a>.  This code is all over, if you search for 'SMTP_TLS ruby.'  </p>
<p>Great! We have the code! This is actually one of my favorite examples of the open source community.  I originally got this code from a guy in Russia, who translated the Japanese page above.  Pretty cool.  Anyway, I don't really want to paste this code above every script I write that sends out an email.  What about a gem!</p>
<blockquote><p>
UPDATE (12/18/07): Well it turns out there already is a gem for this.  <a href="https://rubyforge.org/projects/tlsmail/">TLS Mail</a> is not exactly the same as above, but it does the trick.  The code in this gem is the code in the Ruby 1.9 source. The only catch is that you have to enable the TLS protocol before you send the mail:</p>
<pre class="brush: ruby;">
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
</pre>
<p>Grab the code with "sudo gem install tlsmail"
</p></blockquote>
<p>The <a href="http://rubygems.org/read/chapter/5">RubyGems</a> website has concise, but not overly helpful, documentation about creating gems.  It is pretty easy, though.  I copied the .gemspec file from the simplist gem I could find, and went from there.  I don't know about copy rights or licenses for this code, and this is mostly for internal use, so the gemspec is pretty dumbed down.<br/>
</p>
<pre class="brush: ruby;">

Gem::Specification.new do |s|
  s.name = %q{SMTP_TLS}
  s.version = &quot;1.0.0&quot;
  s.date = %q{2007-12-10}
  s.summary = %q{SMTP TLS (SSL) extension for Net::SMTP}
  s.email = %q{nick@nuclearrooster.com}
  s.homepage = %q{google for smtp_tls}
  s.description = %q{This adds support for TLS (SSL) connections to SMTP mail servers}
  s.has_rdoc = false
  s.authors = [&quot;Dunno&quot;]
  s.files = [&quot;lib/smtp_tls.rb&quot;]
end
</pre>
</p>
<p>Make sure any ruby files are stuck in a lib directory.</p>
<pre class="brush: plain;">

nick-stielaus-computer:~/Desktop/smtp_tls nick$ ls
lib/                    smtp_tls.1.0.0.gemspec
nick-stielaus-computer:~/Desktop/smtp_tls nick$ gem build smtp_tls.1.0.0.gemspec
  Successfully built RubyGem
  Name: SMTP_TLS
  Version: 1.0.0
  File: SMTP_TLS-1.0.0.gem
nick-stielaus-computer:~/Desktop/smtp_tls nick$ sudo gem install SMTP_TLS
Password:
Successfully installed SMTP_TLS, version 1.0.0
</pre>
<p>And then in your scripts</p>
<pre class="brush: ruby;">
  require &quot;net/smtp&quot;
  require &quot;rubygems&quot;
  require &quot;smtp_tls&quot;

  Net::SMTP.start('mail.server.net', 25, 'mail.from.server','usernam', 'password', :login) do |smtp|
    hdr = &quot;From: Me &lt;nick@nuclearrooster.com&gt;\n&quot;
    hdr += &quot;To: Nick Stielau &lt;nick@nuclearrooster.com&gt;\n&quot;
    hdr += &quot;Subject: Subject\n\n&quot;
    msg = hdr + &quot;Email Body&quot;
    smtp.send_message msg, 'nick@nuclearrooster.com'
  end
</pre>
<p>Now I can install this gem on my app servers, etc, and the scripts are good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2007/12/12/creating-a-ruby-gem-for-smtp_tls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Including Ruby Gems in Scripts</title>
		<link>http://dev.nuclearrooster.com/2007/09/25/including-ruby-gems-in-scripts/</link>
		<comments>http://dev.nuclearrooster.com/2007/09/25/including-ruby-gems-in-scripts/#comments</comments>
		<pubDate>Tue, 25 Sep 2007 22:55:06 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[Ruby/Rails]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=18</guid>
		<description><![CDATA[For quite a while, I was trying to write a ruby script to print some growl messages. I was having a hard time loading the growl code, using the "require 'ruby-growl'" syntax. I started digging around and looking at ruby's load path. nicks-computer:~/Desktop/depot nick$ irb irb(main):001:0&#62; puts $: /usr/local/lib/ruby/site_ruby/1.8 /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.9.1 /usr/local/lib/ruby/site_ruby /usr/local/lib/ruby/1.8 /usr/local/lib/ruby/1.8/i686-darwin8.9.1 . =&#62; [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>For quite a while, I was trying to write a ruby script to print some growl messages.  I was having a hard time loading the growl code, using the "require 'ruby-growl'" syntax.  I started digging around and looking at ruby's load path.<br/>
</p>
<pre class="brush: plain;">

nicks-computer:~/Desktop/depot nick$ irb
irb(main):001:0&gt; puts $:
/usr/local/lib/ruby/site_ruby/1.8
/usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.9.1
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/1.8
/usr/local/lib/ruby/1.8/i686-darwin8.9.1
.
=&gt; nil
</pre>
<p>After a while, I got it working and left it as <br/>
</p>
<pre class="brush: ruby;">

require '/usr/lib/ruby/gems/1.8/gems/ruby-growl-1.0.1/lib/ruby-growl.rb'
</pre>
<p>A couple months later I opened the script again, and laughed. Hahaha.  Its as easy as</p>
<pre class="brush: ruby;">

require 'rubygems'
require 'ruby-growl
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2007/09/25/including-ruby-gems-in-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YUMmy. Lucas Chan helped my install ruby on RHEL</title>
		<link>http://dev.nuclearrooster.com/2007/09/18/yummy-lucas-chan-helped-my-install-ruby-on-rhel/</link>
		<comments>http://dev.nuclearrooster.com/2007/09/18/yummy-lucas-chan-helped-my-install-ruby-on-rhel/#comments</comments>
		<pubDate>Wed, 19 Sep 2007 00:13:07 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[Ruby/Rails]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=17</guid>
		<description><![CDATA[I was recently trying to install ruby, rubygems, and rails on a fresh Red Hat install. I was following the trusted Hive Logic install guide for os X, and I figured it wouldn't be that far off from redhat. Ruby compiled smoothly, but while installing RubyGems I came across a zlib error. After some fairly [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently trying to install ruby, rubygems, and rails on a fresh Red Hat install.  I was following the trusted <a href="http://hivelogic.com/narrative/articles/ruby_rails_lighttpd_mysql_tiger">Hive Logic install guide</a> for os X, and I figured it wouldn't be that far off from redhat.   Ruby compiled smoothly, but while installing RubyGems I came across a <a href="http://www.zlib.net/">zlib</a> error.  After some fairly agressive googling, I came upon <a href="http://lucaschan.com/weblog/2007/03/22/installing-ruby-on-rails-on-centosredhat-4x/">Lucas Chan's post</a> on the problem. <br/>
</p>
<p>It worked like a charm.  At first I didn't know what <a href="http://linux.duke.edu/projects/yum/">YUM</a> was, and once I found out it was a package installing I didn't exect to have it.  I surely didn't want to compile that too (unless I was sure there was no other way).  Turns out, Yum was already installed, and I got ruby gems going. Thanks to Lucas, a fellow defaultish wordpress theme blogger.<br/>
</p></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2007/09/18/yummy-lucas-chan-helped-my-install-ruby-on-rhel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Overriding Capistrano</title>
		<link>http://dev.nuclearrooster.com/2007/09/07/overriding-capistrano/</link>
		<comments>http://dev.nuclearrooster.com/2007/09/07/overriding-capistrano/#comments</comments>
		<pubDate>Sat, 08 Sep 2007 00:41:57 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Ruby/Rails]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=15</guid>
		<description><![CDATA[Capistrano rocks for deployment, but I found myself wanting to override some spefic parts of the gem. I realize that I am a little late on the scene, as Capistrano 2.0 is out and about, but this solved some of my problems. Specifically, I wanted to customize the SVN checkout to use sudo, have sudo [...]]]></description>
			<content:encoded><![CDATA[<p>Capistrano rocks for deployment, but I found myself wanting to override some spefic parts of the gem.  I realize that I am a little late on the scene, as <a href="http://www.capify.org/">Capistrano 2.0</a> is out and about, but this solved some of my problems.</p>
<p>Specifically, I wanted to customize the SVN checkout to use sudo, have sudo default to specific user, and add a deployment message to the revisions log. This is all easy to do without editing the capistrano gem.  I looked around the gem source and found the code that I wanted to override, and then pulled it out and tweaked it.</p>
<p>In deploy.rb</p>
<pre class="brush: ruby;">
class ::Capistrano::SCM::Subversion
  alias_method :non_sudo_checkout, :checkout
  def checkout(actor)
    op = 'export'
    command = &quot;sudo -u USER #{svn} #{op} -q --config-dir /home/USER/.subversion -r#{configuration.revision} #{configuration.repository} #{actor.release_path} &amp;&amp;&quot;
   run_checkout(actor, command, &amp;svn_stream_handler(actor))
  end
end

class ::Capistrano::Actor
  alias_method :sudo_with_optional_user, :sudo
  def sudo(command, options={}, &amp;block)
    sudo_with_optional_user(command, {:as =&gt;; 'SUDO_USER'}.merge(options), &amp;block)
  end
end

class ::Capistrano::SCM::Base
  alias_method :logging_commands_without_message, :logging_commands
  def logging_commands(directory = nil)
    log = &quot;#{configuration.deploy_to}/revisions.log&quot;
    &quot;(test -e #{log} || (touch #{log} &amp;&amp; chmod 666 #{log})) &amp;&amp; &quot; +
    &quot;echo `date +\&quot;%Y-%m-%d %H:%M:%S\&quot;` $USER #{configuration.revision} #{directory} '#{configuration.message}' &amp;gt;&amp;gt; #{log};&quot;
  end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2007/09/07/overriding-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Mocha to test Rails associations, and association dependencies</title>
		<link>http://dev.nuclearrooster.com/2007/08/08/using-mocha-to-test-rails-associations-and-association-dependencies/</link>
		<comments>http://dev.nuclearrooster.com/2007/08/08/using-mocha-to-test-rails-associations-and-association-dependencies/#comments</comments>
		<pubDate>Wed, 08 Aug 2007 23:53:40 +0000</pubDate>
		<dc:creator>nick.stielau</dc:creator>
				<category><![CDATA[Ruby/Rails]]></category>

		<guid isPermaLink="false">http://dev.nuclearrooster.com/?p=12</guid>
		<description><![CDATA[I just started using Mocha to mock and stub some of my rails tests, after finding out first-hand that fixtures suck and indeed need fixin'. Here's what I like about Mocha: Easy to use Easy to read Decreases the need for complexly dependant fixtures Speeds up tests once fixtures are removed Not only that, but [...]]]></description>
			<content:encoded><![CDATA[<p>I just started using <a href="http://mocha.rubyforge.org/">Mocha</a> to mock and stub some of my rails tests, after finding out first-hand that <a href="http://glu.ttono.us/articles/2006/08/07/why-fixtures-suck-and-how-we-can-fix-them">fixtures suck</a> and indeed <a href="http://errtheblog.com/post/7708">need fixin'</a>.  Here's what I like about Mocha:</p>
<ul>
<li>Easy to use</li>
<li>Easy to read</li>
<li>Decreases the need for complexly dependant fixtures</li>
<li>Speeds up tests once fixtures are removed</li>
</ul>
<p>Not only that, but Mocha puts some constraints on your tests that force you to be a better tester.  If you mock and stub instead of using fixtures, you need to build your tests up to a complete test from an empty mock, rather than whittling them down from a full Ruby object with lots of data.  For example,</p>
<pre class="brush: ruby;"> def test_items_should_return_uniq_set_of_all_rentals_items

bob = Renter.new

bob.expects(:rentals).returns([stub(:items =&gt; [:item_1, :item_2, :item_3]),

stub(:items =&gt; [:item_3, :item_4, :item_5])])

assert_equal bob.items, [:item_1, :item_2, :item_3, :item_4, :item_5]

end </pre>
<p>Before I might have been tempted to play with the +Item+ objects, but with Mocha, they are just symbols, so the test is more transparent.</p>
<p>I am still grappling with some aspects of Mocha and testing in general.  Like custom SQL.  If you want to test your custom SQL, you need data in the database at some point.  Its seems like the higher level stuff is better for mocking, and the lower level stuff gets a little trickier.  Here is how I tackled testing a ActiveRecord association, and its dependency:</p>
<pre class="brush: ruby;"> require File.dirname(__FILE__) + '/../test_helper'

class RenterTest &amp;lt; Test::Unit::TestCase
def test_rental_association
bob = Renter.new
bob.rentals &lt;&lt; Rental.new
assert !bob.rentals.empty?
end

def test_rental_dependency
bob = Renter.new
bob.rentals &lt;&lt; Rental.new
bob.rentals.first.expects(:destroy)
bob.destroy
end
end
</pre>
<p><a href="http://railscasts.com/episodes/60">Railscasts</a> can get you started.</p>
<p style="font-size: 10px; text-align: right">technorati tags:<a rel="tag" href="http://technorati.com/tag/ruby">ruby</a>, <a rel="tag" href="http://technorati.com/tag/rails">rails</a>, <a rel="tag" href="http://technorati.com/tag/testing">testing</a>, <a rel="tag" href="http://technorati.com/tag/mock">mock</a>, <a rel="tag" href="http://technorati.com/tag/test">test</a>, <a rel="tag" href="http://technorati.com/tag/mocha">mocha</a></p>
<p><!-- technorati tags end --></p>
<p style="text-align: right; font-size: 8px">Blogged with <a title="Flock" target="_new" href="http://www.flock.com/blogged-with-flock">Flock</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.nuclearrooster.com/2007/08/08/using-mocha-to-test-rails-associations-and-association-dependencies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
