<?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>McKinney Station &#187; Dreamhost</title>
	<atom:link href="http://www.mckinneystation.com/categories/dreamhost/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mckinneystation.com</link>
	<description>Ruby on Rails web application development for Dallas/Fort Worth and all of North Texas.</description>
	<lastBuildDate>Wed, 02 Sep 2009 14:29:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Deploying Sinatra Apps on Dreamhost</title>
		<link>http://www.mckinneystation.com/2008/10/09/deploying-sinatra-apps-on-dreamhost/</link>
		<comments>http://www.mckinneystation.com/2008/10/09/deploying-sinatra-apps-on-dreamhost/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 05:22:47 +0000</pubDate>
		<dc:creator>Geoffrey</dc:creator>
				<category><![CDATA[Dallas]]></category>
		<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[Sinatra]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[microapps]]></category>

		<guid isPermaLink="false">http://www.mckinneystation.com/?p=86</guid>
		<description><![CDATA[So I LOVE creating small apps as a way of trying out new things.  The problem is that I rarely deploy them anywhere.  Many end up sitting in my /workspace directory until I decide I need to reclaim the space and probably won&#8217;t work on it ever again.
Recently, the Dallas Relevance folks have [...]]]></description>
			<content:encoded><![CDATA[<p>So I LOVE creating <a href="http://www.mckinneystation.com/2008/06/03/microapps-encourage-hacking/">small apps as a way of trying out new things</a>.  The problem is that I rarely deploy them anywhere.  Many end up sitting in my <code>/workspace</code> directory until I decide I need to reclaim the space and probably won&#8217;t work on it ever again.</p>
<p>Recently, the Dallas <a href="http://www.thinkrelevance.com">Relevance</a> folks have been meeting at Panera while we wait for our office space to materialize.  Most of the time everything works out nicely: free wifi, decent coffee, plenty of room to spread out.  But one thing that doesn&#8217;t work correctly while at Panera is <a href="http://tinyurl.com">tinyurl.com</a>.  For some reason, tinyurl is blocked by Panera filters.  This would be fine for most, but since my twitter friends insist on using tinyurl to post links in their tweets, it is annoying not being able to see what is going on.</p>
<h2>Microapp to the Rescue</h2>
<p>So I figured this would be an opportunity for simple little that let me enter the tinyurl, figure out where it was going to redirect to, and go ahead and redirect me there.  This way I am never accessing the evil tinyurl.com directly from the Panera network, but instead letting my little app do that for me.</p>
<p>The app was pretty easy to write.  I used <a href="http://github.com/bmizerany/sinatra">Sinatra</a> and created one &#8220;controller&#8221; and one &#8220;view&#8221;.  Within a few minutes, Sinatra had &#8220;taken the stage on port 4567&#8243; and my app was working.  Locally.</p>
<h2>Give the app a home</h2>
<p>The next challenge came when I tried to deploy it to my trusty <a href="http://www.dreamhost.com">Dreamhost</a> account.  I love Dreamhost for playing around with small apps.  You get <a href="http://dreamhost.com/hosting.html">unlimited domains,</a> they have <a href="http://dreamhost.com/hosting-panel.html">a pretty cool admin control panel</a>, and they support deploying Rails applications with <a href="http://www.modrails.com/">Passenger Phusion</a>.  And since <a href="http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_rack_based_ruby_application">Passenger Phusion 2.0 supports Rack enabled Ruby apps</a>, I knew I should be able to deploy this new app to my Dreamhost account.  A quick search turned up a useful post with <a href="http://www.gittr.com/index.php/archive/deploying-rack-apps-on-dreamhost-via-passenger-including-sinatra/">information on deploying to Sinatra apps on Dreamhost</a>.  Unfortunately, the first attempt didn&#8217;t work.</p>
<h2>Always check the logs</h2>
<p>So I went to the logs to see what went wrong&#8230; wait there weren&#8217;t any logs!  Fortunately I found this post for <a href="http://www.gittr.com/index.php/archive/logging-with-sinatra-and-passenger-another-try/">logging with Sinatra apps</a>.  Unfortunately, the logs didn&#8217;t help.  Apparently, my problem ran deeper.  So like all good debuggers, I started commenting out code and printing out where I was in the app.  The first thing I commented out was the called to render the view using ERB.  Turns out you can configure where the root of the app is located.  Apparently the root path for a Sinatra app running on Dreamhost is not exactly the path where you deployed it.  <code>Sinatra::Application.default_options[:root]</code> looked like this: </p>
<pre><code>/home/.machinename/username/app.domain.com/Rack: /home/.machinename/username</code></pre>
<h2>Additional configuration needed</h2>
<p>Looking through the Sinatra source turned up the needed configuration changes need:</p>
<pre><code>path = "/path/to/app"

Sinatra::Application.default_options.merge!(
  :root =&gt; path,
  :views =&gt; path + '/views',
  :public =&gt; path + '/public',
  :run =&gt; false,
  :env =&gt; :production
)</code></pre>
<p>A quick deploy later and the application was up and running.  Tomorrow we are meeting at Panera and I will get to see what everyone is tweeting about.</p>
<h2>Addendum: Deployment too?</h2>
<p>Since Sinatra apps are so small, you could just copy everything up to the server manually.  But I like have a little Rake task to do that for me.  It just touches the <code>tmp/restart.txt</code> that Passenger uses to know when to restart and then uses rsync to copy the files up to the server.</p>
<pre><code>desc 'Deploy to the server using rsync'
task :restart do
  sh "touch tmp/restart.txt"
end

desc 'Deploy to the server using rsync'
task :deploy =&gt; :restart do
  cmd = "rsync -ruv * #{USERNAME}@#{DOMAIN}:#{DEPLOY_PATH}"
  sh cmd
end</code></pre>
<h2>Take a look at the code</h2>
<p>I have <a href="http://github.com/gdagley/panera">posted the code on Github</a> for everyone to take a look at.  Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mckinneystation.com/2008/10/09/deploying-sinatra-apps-on-dreamhost/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Google Charts with Rails</title>
		<link>http://www.mckinneystation.com/2008/08/22/using-google-charts-with-rails/</link>
		<comments>http://www.mckinneystation.com/2008/08/22/using-google-charts-with-rails/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 18:10:11 +0000</pubDate>
		<dc:creator>Geoffrey</dc:creator>
				<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[googlecharts]]></category>
		<category><![CDATA[microapps]]></category>

		<guid isPermaLink="false">http://www.mckinneystation.com/?p=85</guid>
		<description><![CDATA[With one of my recent microapps, UnscientificPolls.com, I wanted to show the polling data in more interesting ways than just the vote counts.  Charting was the logical conclusion, but how do it was a more difficult decision.
Some of the criteria I had for choosing the charting solution included: ease of use (it is  [...]]]></description>
			<content:encoded><![CDATA[<p>With one of my recent <a href="/2008/06/03/microapps-encourage-hacking/">microapps</a>, <a href="http://www.unscientificpolls.com">UnscientificPolls.com</a>, I wanted to show the polling data in more interesting ways than just the vote counts.  Charting was the logical conclusion, but how do it was a more difficult decision.</p>
<p>Some of the criteria I had for choosing the charting solution included: ease of use (it is  microapp, of course), compatible with shared hosting environment, fast, easy to customize.</p>
<p>Some of the libraries I looked at included: <a href="http://code.google.com/p/flot/">flot with jquery</a>, <a href="http://nubyonrails.com/pages/gruff">gruff</a>, <a href="http://scruffy.rubyforge.org/">scruffy</a>, <a href="http://nubyonrails.com/pages/sparklines">sparklines</a>, and <a href="http://googlecharts.rubyforge.org/">googlecharts</a>.  I settled on the googlecharts library because I didn&#8217;t need the interactive features of <code>flot</code> and I didn&#8217;t want to worry about RMagick needed for <code>gruff</code>, <code>scruffy</code>, or <code>sparklines</code>. </p>
<h2>Google Charts API</h2>
<p>The <a href="http://code.google.com/apis/chart">Google Charts API</a> is an interesting tool that lets you dynamically generate charts using a &#8220;simple&#8221; URL scheme.   The usage policy is very generous too: &#8220;There&#8217;s no limit to the number of calls per day you can make to the Google Chart API.&#8221;</p>
<p>This would allow me to offload the image generation to Google (who supposedly has quite a bit of computing power) and let my application, in a shared hosting environment, focus on collecting votes.</p>
<h2>Enter <em>googlecharts</em></h2>
<p>The challenge with the Google Charts API &#8220;simple&#8221; url scheme is that it would very tedious to have generate it by concatenating the strings together.  Fortunately, Matt Aimonetti built the <code>googlecharts</code> gem for Ruby.  You can get it from <a href="http://www.rubyforge.org">Rubyforge</a> (<code>gem install googlecharts</code>) or <a href="http://www.github.com">Github</a> (<code>gem install mattetti-googlecharts</code>).  </p>
<h2>Installing <em>googlecharts</em> in my Rails App</h2>
<p>With <code>googlecharts</code> installed on my machine I could start using it, by adding it to my <code>config/environment.rb</code> file.</p>
<pre><code>Rails::Initializer.run do |config|
  config.gem "googlecharts", :lib =&gt; "gchart"
end</code></pre>
<p>Since the file we need to include is named &#8220;gchart&#8221;, not &#8220;googlecharts&#8221;, we have to specify the <code>:lib =&gt; "gchart"</code> option.</p>
<p>I also didn&#8217;t want to worry about installing in on the deployment machine, so I unpacked it to the <code>vendor/gems</code> folder using <code>rake gems:unpack</code>.</p>
<h2>Now to the Charts</h2>
<p>Once all that was in place the challenge was getting the data into a format that would be easy to pass to the library.  It turns out, that wasn&#8217;t too challenging either.</p>
<h3>The Helper</h3>
<p>In my view helper module I created a method that would collect the data needed for the chart.</p>
<pre><code>  def pie_chart poll
    @pie_chart ||= {
      :data =&gt; poll.choices.collect(&amp;:votes_count),
      :colors =&gt; poll.choices.collect {|c| c.winner? ? "264409" : "8A1F11" }
    }
  end</code></pre>
<p>This just loops over the choices and collects the needed data and puts it in an easy to use Hash.</p>
<h3>The View</h3>
<pre><code>    &lt;%= Gchart.pie :size =&gt; '240x160',
                   :title =&gt; 'Vote split',
                   :data =&gt; pie_chart(@poll)[:data],
                   :bar_colors =&gt; pie_chart(@poll)[:colors],
                   :format =&gt; 'image_tag' %&gt;</code></pre>
<p>Using googlecharts Gchart made it easy to build the &#8220;simple&#8221; url needed for a pie chart using the Google Charts API (also supports line, scatter, venn, sparklines, and meter charts)  I didn&#8217;t even have to add the <img /> tag because I could pass the <code>:format =&gt; 'image_tag'</code> and one was generated for me.</p>
<h2>Conclusion</h2>
<p>I was extremely happy with how quick and easy it was to get some simple charts into my application (check them out at <a href="http://www.unscientificpolls.com">UnscientificPolls.com</a>).  The response time from Google seems to be as fast as if the images were stored locally. It also saved me the headache of installing with RMagick.  This is definitely a good fit for simple graphs and charts in a Rails application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mckinneystation.com/2008/08/22/using-google-charts-with-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RESTful Rails and Dreamhost</title>
		<link>http://www.mckinneystation.com/2007/12/17/restful-rails-and-dreamhost/</link>
		<comments>http://www.mckinneystation.com/2007/12/17/restful-rails-and-dreamhost/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 17:33:03 +0000</pubDate>
		<dc:creator>Geoffrey</dc:creator>
				<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[RSpec]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.mckinneystation.com/2007/12/17/restful-rails-and-dreamhost/</guid>
		<description><![CDATA[photo by woodleywonderworks

I recently upgraded StagingTracks.com to use Rails 2.0.  I was excited about so many of the newest features that it seemed the logical thing to do.  I even decided to upgrade RSpec in the process so I would be able to play with some of the new features there too.  [...]]]></description>
			<content:encoded><![CDATA[<div class="shadow right"><img src='http://www.mckinneystation.com/wp-content/uploads/2007/12/train_wreck.jpg' alt='Train Wreck' /><br/><span class="credit">photo by <a href="http://flickr.com/photos/wwworks/">woodleywonderworks</a><br />
</span></div>
<p>I recently upgraded <a href="http://www.stagingtracks.com">StagingTracks.com</a> to use <a href="http://weblog.rubyonrails.com/2007/12/7/rails-2-0-it-s-done">Rails 2.0</a>.  I was excited about so many of the newest features that it seemed the logical thing to do.  I even decided to upgrade <a href="http://rspec.rubyforge.org">RSpec</a> in the process so I would be able to play with <a href="http://blog.davidchelimsky.net/articles/2007/12/14/rspec-1-1">some of the new features</a> there too.  </p>
<p>Unfortunately, despite extensive local spec&#8217;ing, when I <a href="http://capify.org/">deployed the app</a> to Dreamhost, <a href="http://www.stagingtracks.com/posts/view/a_minor_glitch">things did not go as planned</a>.  I was using <a href="http://piston.rubyforge.org/">piston to manage my Rails in the app and all of my plugins</a>, so I didn&#8217;t need to worry about which gems were installed on the server.  What I found was that when users tried to submit new information using the forms on the site, nothing would happen.  Let me correct that: It would look like something happened, but no data was submitted.</p>
<h2>So what was the problem?</h2>
<p>I first started by watching the <code>production.log</code> to see if the data was even getting submitted.  As expected, nothing was coming through.  I then used the <a href="https://addons.mozilla.org/firefox/addon/966">Tamper Data plugin</a> for Firefox to see if I if the data was getting out of the browser.  It was, but something interesting appeared.  I saw a 301 Redirect when the page was submitted.  Odd.  Especially since the application wasn&#8217;t seeing the data and there were no redirects in the production.log.  </p>
<p>So I started looking in the http <code>access.log</code> to see why the data wasn&#8217;t coming through to the app.  What I saw was surprising:</p>
<pre>
<code>- - [16/Dec/2007:19:24:30 -0800] "POST /shops HTTP/1.1" 301 591 "http://www.stagingtracks.com/shops/new" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"
- - [16/Dec/2007:19:24:30 -0800] "GET /shops/ HTTP/1.1" 200 319 "http://www.stagingtracks.com/shops/new" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"</code></pre>
<p>It looked like the POST (which goes to the &#8216;create&#8217; method using Rails RESTful approach) was being redirected to &#8216;/shops/&#8217;.  The browser would then call &#8216;/shops/ &#8216; with a GET (which is the &#8216;index&#8217; action).  And the form submission never got through.  Now I was perplexed.  Why would the web server being sending the 301 Redirect?</p>
<p>It became a little clearer when I saw this in the logs as well:</p>
<pre>
<code>- - [16/Dec/2007:19:15:11 -0800] "GET /shops HTTP/1.1" 301 591 "http://www.stagingtracks.com/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"
- - [16/Dec/2007:19:15:11 -0800] "GET /shops/ HTTP/1.1" 200 89174 "http://www.stagingtracks.com/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11"</code></pre>
<p>For some reason, the web server was causing 301 Redirects when the trailing slash was missing!  Now I had heard of <a href="http://www.google.com/search?q=trailing+slash+rails">the trailing slash problem</a>, but couldn&#8217;t find a suitable solution that would be easy to implement.</p>
<h2>So How Do You Fix It?</h2>
<p>I am so glad I am surrounded by lots of smart people.  A quick conversation with my friend <a href="http://robsanheim.com/">Rob Sanheim</a> turned up <a href="http://mephisto.stikipad.com/help/show/Developer+Tips">the solution</a>.  </p>
<p>I added the following to my <code>.htaccess</code> file:</p>
<pre>
<code>DirectorySlash Off</code>
</pre>
<p>I added it after the <code>Options +FollowSymLinks +ExecCGI</code> and before the <code>RewriteEngine On</code></p>
<p>Now things are back to normal again.  I am now able to get back to <a href="http://www.stagingtracks.com">connecting model railroaders</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mckinneystation.com/2007/12/17/restful-rails-and-dreamhost/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
