<?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>Paul Goscicki &#187; rails</title>
	<atom:link href="http://paulgoscicki.com/categories/programming/ruby/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://paulgoscicki.com</link>
	<description>Random pieces of code, thoughts and movie reviews</description>
	<lastBuildDate>Tue, 15 Nov 2011 18:45:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Tell bundler to install gems globally when using capistrano</title>
		<link>http://paulgoscicki.com/archives/2011/10/tell-bundler-to-install-gems-globally-when-using-capistrano/</link>
		<comments>http://paulgoscicki.com/archives/2011/10/tell-bundler-to-install-gems-globally-when-using-capistrano/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 18:00:51 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/?p=372</guid>
		<description><![CDATA[Seems like it&#8217;s not so straightforward. Here&#8217;s the excerpt from my config/deploy.rb: require "bundler/capistrano" set :bundle_dir, "" # install into "system" gems set :bundle_flags, "--quiet" # no verbose output set :bundle_without, [] # bundle all gems (even dev &#038; test) Maybe someone finds it helpful.]]></description>
			<content:encoded><![CDATA[<p>Seems like it&#8217;s not so straightforward. Here&#8217;s the excerpt from my <code>config/deploy.rb</code>:</p>
<pre class="code">
require "bundler/capistrano"
set :bundle_dir,     ""         # install into "system" gems
set :bundle_flags,   "--quiet"  # no verbose output
set :bundle_without, []         # bundle all gems (even dev &#038; test)
</pre>
<p>Maybe someone finds it helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2011/10/tell-bundler-to-install-gems-globally-when-using-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bug of the day</title>
		<link>http://paulgoscicki.com/archives/2011/09/bug-of-the-day/</link>
		<comments>http://paulgoscicki.com/archives/2011/09/bug-of-the-day/#comments</comments>
		<pubDate>Wed, 28 Sep 2011 16:52:40 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/?p=360</guid>
		<description><![CDATA[Completely bad code follows, beware. Silent error in Ruby 1.8.7: x = [:a, :b] => [:a, :b] x.slice!(:a) => nil x => [:a, :b] Explicit error (resulting in a failing test) in Ruby 1.9.2: x = [:a, :b] => [:a, :b] x.slice!(:a) TypeError: can't convert Symbol into Integer Just yet another incompatibility, but for the [...]]]></description>
			<content:encoded><![CDATA[<p>Completely <strong>bad code</strong> follows, beware.</p>
<p>Silent error in Ruby 1.8.7:</p>
<pre class="code">
x = [:a, :b]
=> [:a, :b]

x.slice!(:a)
=> nil

x
=> [:a, :b]
</pre>
<p>Explicit error (resulting in a failing test) in Ruby 1.9.2:</p>
<pre class="code">
x = [:a, :b]
=> [:a, :b]

x.slice!(:a)
TypeError: can't convert Symbol into Integer
</pre>
<p>Just yet another incompatibility, but for the better!</p>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2011/09/bug-of-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run guard-jasmine-headless-webkit without X server</title>
		<link>http://paulgoscicki.com/archives/2011/09/run-guard-jasmine-headless-webkit-without-x-server/</link>
		<comments>http://paulgoscicki.com/archives/2011/09/run-guard-jasmine-headless-webkit-without-x-server/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 17:44:38 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/?p=355</guid>
		<description><![CDATA[You write specs for your javascript, right? If not, you really should. jasmine-headless-webkit really helps with that. guard-jasmine-headless-webkit makes it all even more enjoyable, although there&#8217;s one caveat &#8211; it&#8217;s not so easy to set it all up. There is a great guide for that, but it lacks some important details on running guard-jasmine-headless-webkit without [...]]]></description>
			<content:encoded><![CDATA[<p>You write specs for your javascript, right? If not, you <a href="http://gilesbowkett.blogspot.com/2011/08/tdd-in-javascript-no-excuses.html">really</a> <a href="http://railscasts.com/episodes/261-testing-javascript-with-jasmine">should</a>.</p>
<p><a href="https://github.com/johnbintz/jasmine-headless-webkit">jasmine-headless-webkit</a> really helps with that. <a href="https://github.com/johnbintz/guard-jasmine-headless-webkit">guard-jasmine-headless-webkit</a> makes it all even more enjoyable, although there&#8217;s one caveat &#8211; it&#8217;s not so easy to set it all up.</p>
<p>There is a <a href="http://johnbintz.github.com/jasmine-headless-webkit/">great guide</a> for that, but it lacks some important details on running <code>guard-jasmine-headless-webkit</code> without graphical interface (X server).</p>
<p>Assuming you already have Xvfb installed, execute this command to run Xvfb in the background:</p>
<pre class="code">
Xvfb :0 -screen 0 1024x768x24 > /dev/null 2>&#038;1 &#038;
</pre>
<p>And then you need to setup the <code>DISPLAY</code> shell variable in order for <code>guard-jasmine-headless-webkit</code> to automatically connect to our virtual frame buffer. Here&#8217;s the excerpt from my <a href="https://github.com/pjg/dotfiles/blob/master/.bash_profile">.bash_profile</a> (it first checks if there is Xvfb running on display :0 and only then sets the DISPLAY variable):</p>
<pre class="code">
xdpyinfo -display :0 &#038;>/dev/null &#038;&#038; export DISPLAY=:0
</pre>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2011/09/run-guard-jasmine-headless-webkit-without-x-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>hookup is the shit!</title>
		<link>http://paulgoscicki.com/archives/2011/06/hookup-is-the-shit/</link>
		<comments>http://paulgoscicki.com/archives/2011/06/hookup-is-the-shit/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 19:41:14 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/?p=319</guid>
		<description><![CDATA[This is simply amazing: $ g pull Already up-to-date. $ g co edge Switched to branch 'edge' == AddFileTypeToSong: migrating ============================================== -- add_column(:songs, :file_type, :string) -> 0.0048s == AddFileTypeToSong: migrated (0.1380s) ===================================== $ g rebase master Current branch edge is up to date. $ g co master Switched to branch 'master' == AddFileTypeToSong: reverting ============================================== [...]]]></description>
			<content:encoded><![CDATA[<p>This is simply amazing:</p>
<pre class="code">
$ g pull
Already up-to-date.

$ g co edge
Switched to branch 'edge'
==  AddFileTypeToSong: migrating ==============================================
-- add_column(:songs, :file_type, :string)
   -> 0.0048s
==  AddFileTypeToSong: migrated (0.1380s) =====================================

$ g rebase master
Current branch edge is up to date.

$ g co master
Switched to branch 'master'
==  AddFileTypeToSong: reverting ==============================================
-- remove_column(:songs, :file_type)
   -> 0.1674s
==  AddFileTypeToSong: reverted (0.1679s) =========================
</pre>
<p>Oh, and it will bundle automatically for you as well, so don&#8217;t hesitate and <a href="https://github.com/tpope/hookup">hookup your Rails project</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2011/06/hookup-is-the-shit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>On Heroku</title>
		<link>http://paulgoscicki.com/archives/2011/02/on-heroku/</link>
		<comments>http://paulgoscicki.com/archives/2011/02/on-heroku/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 16:18:32 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[hosting]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/?p=302</guid>
		<description><![CDATA[While Heroku is nice and all, it suffers from the same disease as every other hosted-for-you solution: $ git push heroku (...) -----> Gemfile detected, running Bundler version 1.0.7 (...) $ bundle --version Bundler version 1.0.10 It&#8217;s a whole three patch versions behind! Now I don&#8217;t really know (and maybe don&#8217;t even really want to [...]]]></description>
			<content:encoded><![CDATA[<p>While <a href="http://heroku.com/">Heroku</a> is nice and all, it suffers from the same disease as every other <em>hosted-for-you</em> solution:</p>
<pre class="code">
$ git push heroku
(...)
-----> Gemfile detected, running Bundler version 1.0.7
(...)

$ bundle --version
Bundler version 1.0.10
</pre>
<p>It&#8217;s a whole three <a href="http://semver.org/">patch versions</a> behind! Now I don&#8217;t really know (and maybe don&#8217;t even really want to know) what has changed between .7 and .10, but I can easily imagine things braking precisely because those minor inconsistencies in Bundler versions.</p>
<p>And sure, I could downgrade to .7, but to do that just because of Heroku? Thank you, but no. I want to ride the latest.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2011/02/on-heroku/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mocha. The stubbing library</title>
		<link>http://paulgoscicki.com/archives/2009/05/mocha-the-stubbing-library/</link>
		<comments>http://paulgoscicki.com/archives/2009/05/mocha-the-stubbing-library/#comments</comments>
		<pubDate>Tue, 26 May 2009 13:51:41 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/?p=257</guid>
		<description><![CDATA[This example (shortened here): class Order def shipping_cost total_weight * 5 + 10 end end require 'test/unit' require 'rubygems' require 'mocha' class OrderTest < Test::Unit::TestCase # illustrates stubbing instance method def test_should_calculate_shipping_cost_based_on_total_weight order = Order.new order.stubs(:total_weight).returns(10) assert_equal 60, order.shipping_cost end end and this snippet (emphasis mine): The more interesting discussion deals with whether to mock [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mocha.rubyforge.org/examples/stubba.html">This example</a> (shortened here):</p>
<pre class="code">
class Order
  def shipping_cost
    total_weight * 5 + 10
  end
end

require 'test/unit'
require 'rubygems'
require 'mocha'

class OrderTest < Test::Unit::TestCase
  # illustrates stubbing instance method
  def test_should_calculate_shipping_cost_based_on_total_weight
    order = Order.new
    order.stubs(:total_weight).returns(10)
    assert_equal 60, order.shipping_cost
  end
end
</pre>
<p>and <a href="http://www.ibm.com/developerworks/web/library/wa-rails4/">this snippet</a> (emphasis mine):</p>
<blockquote><p>The more interesting discussion deals with whether to mock or stub your database-backed model. One upside is speed: This test case will not hit the database at all. Another is independence. I completely <strong>isolate the code under test to the controller layer</strong>. </p></blockquote>
<p>convinced me that there just might be some treasure to be found beyond the <code>Test::Unit</code>. And I <em>know</em> that it's just the tip of the iceberg.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2009/05/mocha-the-stubbing-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails and Merb together</title>
		<link>http://paulgoscicki.com/archives/2008/12/rails-and-merb-together/</link>
		<comments>http://paulgoscicki.com/archives/2008/12/rails-and-merb-together/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 12:04:22 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/?p=190</guid>
		<description><![CDATA[Or putting it in another words: Merb will be merged into Rails to become Rails 3.0. Is it 1st April just way too soon or what? &#8211; was my first thought the moment I&#8217;ve read it on the Ezra&#8217;s blog. But then I&#8217;ve read the official announcement and&#8230; it kind of turned out to be [...]]]></description>
			<content:encoded><![CDATA[<p>Or putting it in another words: Merb will be <a href="http://rubyonrails.org/merb">merged</a> into Rails to become Rails 3.0. <em>Is it 1st April just way too soon or what?</em> &#8211; was my first thought the moment I&#8217;ve read it on the <a href="http://brainspl.at/articles/2008/12/23/merb-is-rails">Ezra&#8217;s blog</a>. But then I&#8217;ve read the <a href="http://weblog.rubyonrails.org/2008/12/23/merb-gets-merged-into-rails-3">official announcement</a> and&#8230; it kind of turned out to be true. Surprised I was, definitely. I haven&#8217;t really jumped on the whole Merb bandwagon. Sure, I was planning to try out Merb in the (rather distant) future. Now it seems I won&#8217;t have to. Merb supposedly did lots of things better than Rails (modularity, less dependencies, more lightweight, faster) and those things are to be incorporated into Rails. Will see how this pans out.</p>
<p>Exciting times. Definitely exciting. Nice Xmas gift.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2008/12/rails-and-merb-together/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails helpers. Rediscovered</title>
		<link>http://paulgoscicki.com/archives/2008/04/rails-helpers-rediscovered/</link>
		<comments>http://paulgoscicki.com/archives/2008/04/rails-helpers-rediscovered/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 08:15:08 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/archives/2008/04/rails-helpers-rediscovered/</guid>
		<description><![CDATA[Normally, you&#8217;d use partials to manage some common functionality in a single file. For example like this: Somewhere in your view: &#60;%= render :partial =&#62; 'ads/ad', :locals =&#62; {:placement =&#62; 'frontpage-banner1'} %&#62; It&#8217;s quite concise, but how about making it even less verbose? Helpers to the rescue: module AdsHelper def ad(placement) render :partial =&#62; 'ads/ad', [...]]]></description>
			<content:encoded><![CDATA[<p>Normally, you&#8217;d use partials to manage some common functionality in a single file. For example like this:</p>
<p>Somewhere in your view:</p>
<pre class="code">
&lt;%= render :partial =&gt; 'ads/ad', :locals =&gt; {:placement =&gt; 'frontpage-banner1'} %&gt;
</pre>
<p>It&#8217;s quite concise, but how about making it even less verbose? Helpers to the rescue:</p>
<pre class="code">
module AdsHelper
  def ad(placement)
    render :partial =&gt; 'ads/ad', :locals =&gt; {:placement =&gt; placement}
  end
end
</pre>
<p>And now you can write this in your view:</p>
<pre class="code">
&lt;%= ad 'frontpage-banner1' %&gt;
</pre>
<p>Nice! I believe it&#8217;s as short as it gets. Sure, if you render this partial only a few times it might not be worth it, but what if you render it 20 or 30 times?</p>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2008/04/rails-helpers-rediscovered/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>content_tag FTW!</title>
		<link>http://paulgoscicki.com/archives/2008/04/content_tag-ftw/</link>
		<comments>http://paulgoscicki.com/archives/2008/04/content_tag-ftw/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 20:36:31 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/archives/2008/04/content_tag-ftw/</guid>
		<description><![CDATA[About those one-liners&#8230; How about turning this: &#60;% if logged_in? then %&#62; &#60;p&#62;&#60;%= link_to 'Edit', document_edit_path(@document) %&#62;&#60;/p&#62; &#60;% end %&#62; into this: &#60;%= content_tag 'p', link_to('Edit', document_edit_path(@document)) if logged_in? %&#62; I don&#8217;t know about you, but to say that I&#8217;m impressed would be not enough. Available from Rails 2.0 upwards.]]></description>
			<content:encoded><![CDATA[<p>About those <a href="/archives/2008/04/steve-yegge-again/">one-liners</a>&#8230; How about turning this:</p>
<pre class="code">
&lt;% if logged_in? then %&gt;
&lt;p&gt;&lt;%= link_to 'Edit', document_edit_path(@document) %&gt;&lt;/p&gt;
&lt;% end %&gt;
</pre>
<p>into this:</p>
<pre class="code">
&lt;%= content_tag 'p', link_to('Edit', document_edit_path(@document)) if logged_in? %&gt;
</pre>
<p>I don&#8217;t know about you, but to say that I&#8217;m impressed would be not enough. Available from <a href="http://www.rubyonrails.org/">Rails 2.0</a> upwards.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2008/04/content_tag-ftw/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mongrel_cluster not starting after hard reboot</title>
		<link>http://paulgoscicki.com/archives/2008/03/mongrel_cluster-not-starting-after-hard-reboot/</link>
		<comments>http://paulgoscicki.com/archives/2008/03/mongrel_cluster-not-starting-after-hard-reboot/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 12:27:42 +0000</pubDate>
		<dc:creator>Paul Goscicki</dc:creator>
				<category><![CDATA[administration]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://paulgoscicki.com/archives/2008/03/mongrel_cluster-not-starting-after-hard-reboot/</guid>
		<description><![CDATA[Does the following error sound familiar? ** !!! PID file log/mongrel.pid already exists. Mongrel could be running already. Check your log/mongrel.log for errors. ** !!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start. It usually happens when the server crashes. After that you need to ssh into [...]]]></description>
			<content:encoded><![CDATA[<p>Does the following error sound familiar?</p>
<pre class="code">
<code>** !!! PID file log/mongrel.pid already exists.  Mongrel could be running already.  Check your log/mongrel.log for errors.
** !!! Exiting with error.  You must stop mongrel and clear the .pid before I'll attempt a start.
</code>
</pre>
<p>It usually happens when the server crashes. After that you need to ssh into it, remove the mongrel pid files and start the cluster manually. No more.</p>
<p>I assume you have <code>mongrel_cluster</code> setup properly, ie: project&#8217;s config file is in <code>/etc/mongrel_cluster</code> and the<code> mongrel_cluster</code> script has been copied from:<br />
<code>/usr/lib/ruby/gems/1.8/gems/mongrel_cluster-*/resources/</code><br />
to the <code>/etc/init.d</code> directory. You need to edit the /etc/init.d/mongrel_cluster file:</p>
<p>Change this two bits:</p>
<pre class="code">
<code>start)
  # Create pid directory
  mkdir -p $PID_DIR
  chown $USER:$USER $PID_DIR

  mongrel_cluster_ctl start -c $CONF_DIR
  RETVAL=$?
;;</code>
</pre>
<p>and</p>
<pre class="code">
<code>restart)
  mongrel_cluster_ctl restart -c $CONF_DIR
  RETVAL=$?
;;</code>
</pre>
<p>to</p>
<pre class="code">
<code>start)
  # Create pid directory
  mkdir -p $PID_DIR
  chown $USER:$USER $PID_DIR

  mongrel_cluster_ctl start --clean -c $CONF_DIR
  RETVAL=$?
;;</code>
</pre>
<p>and</p>
<pre class="code">
<code>restart)
  mongrel_cluster_ctl restart --clean -c $CONF_DIR
  RETVAL=$?
;;</code>
</pre>
<p>respectively.</p>
<p>Adding the <code>--clean</code> option makes the <code>mongrel_cluster_ctl</code> script first check whether <code>mongrel_rails</code> processes are running and if not, checks for existing pid files and deletes them before proceeding.</p>
<p>You must be using the <code>mongrel_cluster</code> version 1.0.5+ for it to work as advertised (previous versions were buggy). To upgrade do:</p>
<pre class="code">
<code>gem install mongrel_cluster
gem cleanup mongrel_cluster</code>
</pre>
<p>Here&#8217;s the related <a href="http://rubyforge.org/tracker/index.php?func=detail&#038;aid=12558&#038;group_id=1306&#038;atid=5147">mongrel_cluster changeset</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://paulgoscicki.com/archives/2008/03/mongrel_cluster-not-starting-after-hard-reboot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

