<?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>not so silent (e) &#187; ruby on rails</title>
	<atom:link href="http://notso.silent-e.com/category/programming/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://notso.silent-e.com</link>
	<description>Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind. - Dr. Seuss</description>
	<lastBuildDate>Tue, 31 Jan 2012 00:20:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>OSX Passenger prefpane tip</title>
		<link>http://notso.silent-e.com/2011/01/06/osx-passenger-prefpane-tip/</link>
		<comments>http://notso.silent-e.com/2011/01/06/osx-passenger-prefpane-tip/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 19:44:22 +0000</pubDate>
		<dc:creator>matte</dc:creator>
				<category><![CDATA[note to self]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://notso.silent-e.com/?p=1035</guid>
		<description><![CDATA[I recently undid all my MacPorts and started using Homebrew for some software on my Macs. That meant uninstalling the Apache MacPort and switching back to the default Snow Leopard version of Apache. Everything went relatively smoothly but today a noticed that my Passenger prefpane wasn&#8217;t listing all the Rails sites it had previously been [...]]]></description>
			<content:encoded><![CDATA[<p>I recently undid all my MacPorts and started using Homebrew for some software on my Macs.  That meant uninstalling the Apache MacPort and switching back to the default Snow Leopard version of Apache.  Everything went relatively smoothly but today a noticed that my <a href="http://www.fngtps.com/passenger-preference-pane">Passenger prefpane</a> wasn&#8217;t listing all the Rails sites it had previously been managing.</p>
<p>Turns out it was because in my original install of the prefpane I had used the &#8220;ports&#8221; version of a required ruby file, per instructions, since I was using the MacPort version of Apache.  The easy fix is to just reinstall the prefpane.  All of my sites now show up in the site listing and I can add the new site I&#8217;m currently developing.</p>
]]></content:encoded>
			<wfw:commentRss>http://notso.silent-e.com/2011/01/06/osx-passenger-prefpane-tip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing Snarl and autotest_menu in windows</title>
		<link>http://notso.silent-e.com/2009/04/09/fixing-snarl-and-autotest-menu-in-windows/</link>
		<comments>http://notso.silent-e.com/2009/04/09/fixing-snarl-and-autotest-menu-in-windows/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 19:33:24 +0000</pubDate>
		<dc:creator>matte</dc:creator>
				<category><![CDATA[me me me]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://notso.silent-e.com/?p=721</guid>
		<description><![CDATA[I&#8217;ve been trying to get ZenSpider autotest and Windows to play nice for a while. First, I had the problem where autotest would only run once and not stick around waiting for updates to my code. That was fixed by Luke Pearce. He commented on a previous post with his fix and I can confirm [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to get ZenSpider autotest and Windows to play nice for a while.  First, I had the problem where autotest would only run once and not stick around waiting for updates to my code.  That was fixed by <a href="http://www.kulesolutions.com/" target="_blank">Luke Pearce</a>.  He <a href="http://notso.silent-e.com/2009/04/06/turning-off-the-rails-232-backtracecleaner/#comment-9523" target="_blank">commented on a previous post</a> with his fix and I can confirm that it works.  Thanx Luke!</p>
<p>I encountered another problem now.  When I ran my autotest but tried to shut it down by hitting Control-C twice in a row, the tests would just reset and run again.  Double Control-C is supposed to interrupt the process and allow me to shut it down.  This it did not do.<br />
<span id="more-721"></span><br />
I am also running the autotest/menu plugin that is supposed to explicitly ask you whether you want to quit, restart or just keep going when you hit Control-C, even if it&#8217;s just hitting it once.  This is the best possible option and is what I recommend, but it wasn&#8217;t happening.  There were no prompts to quit, continue, or restart.  Just restarting the entire test suite EVERY time I hit Control-C, whether it was two quick hits or 10 hits a row.</p>
<p>I originally looked at the code thinking that I should fix it there.  Autotest provides hooks into it&#8217;s process.  Run, interrupt, quit, etc.  I figured it had to do with one of those so I first tried just commenting out the :interrupt hook code on lines 39-41 in ZenTest-4.0.0/lib/autotest/snarl.rb.  This worked and I was happy.  However it still didn&#8217;t feel right.  I didn&#8217;t want to hack the code and ask them to fix it.  It must be working for other people because I haven&#8217;t seen other people complaining about it.</p>
<p>Turns out the fix is a really easy one and requires no hacking on the gem code at all.  It was just a problem with the order of my &#8220;require&#8221; lines in my .autotest file.  My original .autotest file looked like this&#8230;</p>
<p><code>require 'redgreen/autotest'<br />
require 'Win32/Console/ANSI'<br />
require 'autotest/snarl'<br />
require 'autotest/menu'<br />
require 'autotest/timestamp'</code></p>
<p>The .autotest file that WORKS swaps the &#8220;snarl&#8221; and &#8220;menu&#8221; lines around, like so&#8230;</p>
<p><code>require 'redgreen/autotest'<br />
require 'Win32/Console/ANSI'<br />
require 'autotest/menu'<br />
require 'autotest/snarl'<br />
require 'autotest/timestamp'</code></p>
]]></content:encoded>
			<wfw:commentRss>http://notso.silent-e.com/2009/04/09/fixing-snarl-and-autotest-menu-in-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turning off the Rails 2.3.2 BacktraceCleaner</title>
		<link>http://notso.silent-e.com/2009/04/06/turning-off-the-rails-232-backtracecleaner/</link>
		<comments>http://notso.silent-e.com/2009/04/06/turning-off-the-rails-232-backtracecleaner/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 23:27:38 +0000</pubDate>
		<dc:creator>matte</dc:creator>
				<category><![CDATA[me me me]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://notso.silent-e.com/?p=714</guid>
		<description><![CDATA[I had a situation today where, when running some functional tests, the error backtrace being displayed was not helpful at ALL. I was defining a layout for a controller as a symbol instead of a string like I should have been using. You use a string when you are just saying &#8220;Use this layout&#8221; and [...]]]></description>
			<content:encoded><![CDATA[<p>I had a situation today where, when running some functional tests, the error backtrace being displayed was not helpful at ALL.  I was defining a layout for a controller as a symbol instead of a string like I should have been using.  You use a string when you are just saying &#8220;Use this layout&#8221; and you use a symbol when you have a method to call that responds with the layout to use.  The error I was getting was &#8230;</p>
<p><code>NoMethodError: undefined method `admin' for #&lt;Admin::RegistrationsController&gt;</code></p>
<p>but what was the first line that came up in the backtrace?</p>
<p><code>app/controllers/admin/registrations_controller.rb:18:in `show'</code></p>
<p>This was giving me fits.  There&#8217;s no call to &#8216;admin&#8217; in the &#8216;show&#8217; method.  I knew there had to be something else so I searched for how to see more of the backtrace.</p>
<p>The BacktraceCleaner <a href="http://guides.rubyonrails.org/2_3_release_notes.html#quieter-backtraces" target="_blank">introduced in Rails 2.3.2</a> cleans out backtrace lines coming from the Rails framework (Railties, etc).  This is usually what you want.  However, I was sure that my error was coming from somewhere in the framework.  Turns out it&#8217;s really simple to turn off the backtrace cleaner.  Add this line in a &#8216;setup&#8217; method in your test_helper.rb file.</p>
<p><code>Rails.backtrace_cleaner.remove_silencers!</code></p>
<p>Very simple, very easy.  My name is Chef Tell.  <img src='http://notso.silent-e.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://notso.silent-e.com/2009/04/06/turning-off-the-rails-232-backtracecleaner/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rails 2.3.2 and testing with assert_select_email</title>
		<link>http://notso.silent-e.com/2009/04/02/rails-232-and-testing-with-assert_select_email/</link>
		<comments>http://notso.silent-e.com/2009/04/02/rails-232-and-testing-with-assert_select_email/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 22:38:48 +0000</pubDate>
		<dc:creator>matte</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://notso.silent-e.com/2009/04/02/rails-232-and-testing-with-assert_select_email/</guid>
		<description><![CDATA[I upgraded a project to Rails 2.3.2 a while back and have been getting the following error when running some unit tests&#8230; NoMethodError: undefined method `assert_select_email' for #&#60;UserMailerTest&#62; I posted to the rubyonrails-talk google group but never got a response, and I was not the first to post about this problem to that group. However [...]]]></description>
			<content:encoded><![CDATA[<p>I upgraded a project to Rails 2.3.2 a while back and have been getting the following error when running some unit tests&#8230;</p>
<p><code>NoMethodError: undefined method `assert_select_email' for #&lt;UserMailerTest&gt;</code></p>
<p>I <a href="http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/fabaf2c73943e268" target="_blank">posted to the rubyonrails-talk google group</a> but never got a response, and I was not the first to post about this problem to that group.  However I found someone else commenting on this in an <a href="https://rspec.lighthouseapp.com/projects/5645/tickets/736-no-access-to" target="_blank">rspec lighthouse ticket</a> and they&#8217;d fixed it for their setup.  It was an easy conversion to non-rspec and here&#8217;s the line you need to add to your test/test_helper.rb file</p>
<p><code>include ActionController::Assertions::SelectorAssertions</code></p>
<p>I&#8217;m not sure why it&#8217;s broken but it appears to have regressed in one of the Rails 2.3.2 RCs.</p>
]]></content:encoded>
			<wfw:commentRss>http://notso.silent-e.com/2009/04/02/rails-232-and-testing-with-assert_select_email/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>log_buddy and Windows</title>
		<link>http://notso.silent-e.com/2008/07/10/log_buddy-and-windows/</link>
		<comments>http://notso.silent-e.com/2008/07/10/log_buddy-and-windows/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 18:57:22 +0000</pubDate>
		<dc:creator>matte</dc:creator>
				<category><![CDATA[note to self]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://notso.silent-e.com/?p=533</guid>
		<description><![CDATA[I recently started playing around with the log_buddy gem for Rails and because my development machine is on windows, the &#8220;d&#8221; method wasn&#8217;t playing nice with some paths.  it didn&#8217;t like paths that included the drive letter. this is a sample of a line that would cause log_buddy to barf.  it just so happens to [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started playing around with the log_buddy gem for Rails and because my development machine is on windows, the &#8220;d&#8221; method wasn&#8217;t playing nice with some paths.  it didn&#8217;t like paths that included the drive letter.</p>
<p>this is a sample of a line that would cause log_buddy to barf.  it just so happens to also be the line that causes the error.  <img src='http://notso.silent-e.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><code>c:/ruby/lib/ruby/gems/1.8/gems/log_buddy-0.0.5/lib/log_buddy.rb:98:in `read_line'</code></p>
<p>the original line looked like this&#8230;</p>
<p><code>file, line_number = frame.split(/:/, 2)</code></p>
<p>the fix is to replace that line with</p>
<p><code>file, line_number = frame.reverse.split(/:/, 3)[1..2].map(&amp;:reverse).reverse</code></p>
<p>yeah.  ugly, and maybe could be written better but it works for me.</p>
<p>now if only I could get log_buddy to output good inspections of objects I toss to it&#8230; like &#8220;current_user&#8221;.  I&#8217;m prolly using it wrong right now, but this isn&#8217;t helpful&#8230;</p>
<p><code>current_user = '#&lt;User:0x47143d8&gt;'</code></p>
<p>just saying.  <img src='http://notso.silent-e.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>UPDATE: I monkeypatched log_buddy to fix this functionality.  I created a &#8220;RAILS_ROOT/lib/log_buddy_extensions.rb&#8221; file with the following code.</p>
<pre><code>class LogBuddy

  private

  # Return the calling line
  def self.read_line(frame)
    file, line_number = frame.reverse.split(/:/, 3)[1..2].map(&#038;:reverse).reverse
    line_number = line_number.to_i
    lines = File.readlines(file)
    lines[line_number - 1]
  end

end</code></pre>
<p>and I figured out that the &#8220;current_user&#8221; line above shouldn&#8217;t be &#8230;</p>
<p><code>d { current_user }</code></p>
<p>it should be</p>
<p><code>d { current_user.inspect }</code></p>
<p>that outputs what I want &#8230;</p>
<p><code>current_user.inspect = '#&lt;User id: 1, login: "matte", email: "matte@localhost", crypted_password: "...", salt: "...", created_at: "2007-08-30 18:23:32", updated_at: "2008-07-08 18:57:45", remember_token: "...", remember_token_expires_at: "2008-07-22 18:57:45", name: "...", password_reset_code: nil, company_id: 2, active: true&gt;'</code></p>
]]></content:encoded>
			<wfw:commentRss>http://notso.silent-e.com/2008/07/10/log_buddy-and-windows/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>before_create gotcha with BetterNestedSet plugin</title>
		<link>http://notso.silent-e.com/2008/02/14/before_create-gotcha-with-betternestedset-plugin/</link>
		<comments>http://notso.silent-e.com/2008/02/14/before_create-gotcha-with-betternestedset-plugin/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 20:37:16 +0000</pubDate>
		<dc:creator>matte</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://notso.silent-e.com/2008/02/14/before_create-gotcha-with-betternestedset-plugin/</guid>
		<description><![CDATA[I&#8217;m using BetterNestedSet at work in my Rails work but I&#8217;ve been having trouble understanding why my code was giving me an error of &#8220;Impossible move, target node cannot be inside moved tree&#8221;. I&#8217;m trying to create Categories, scoped to certain CategoryTypes. Pretty standard associations. Categories belong_to CategoryTypes CategoryTypes has_many Categories The one thing I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using <a href="http://opensource.symetrie.com/trac/better_nested_set/" title="BetterNestedSet" target="_blank">BetterNestedSet</a> at work in my Rails work but I&#8217;ve been having trouble understanding why my code was giving me an error of &#8220;Impossible move, target node cannot be inside moved tree&#8221;.<br />
<span id="more-490"></span><br />
I&#8217;m trying to create Categories, scoped to certain CategoryTypes.  Pretty standard associations.</p>
<p>Categories belong_to CategoryTypes<br />
CategoryTypes has_many Categories</p>
<p>The one thing I&#8217;m doing a little different from the BNS readme is that I&#8217;m not assigning my scope column id directly.  I&#8217;m using one of Jamis Buck&#8217;s recommendations.</p>
<p><a href="http://weblog.jamisbuck.org/2007/1/11/moving-associated-creations-to-the-model" target="_blank">Moving associated creations to the model</a></p>
<p>I have a &#8220;data&#8221; attribute subset of fields in my form.  It&#8217;s just one field &#8220;category_type&#8221;.  Note, not category_type_id.  It&#8217;s just a choice I made.  This gives me the following params being passed to the controller&#8230;</p>
<pre><code>{ :text =&gt; 'Tom Servo', :data =&gt; { :category_type =&gt; 1 } }</code></pre>
<p>Then in a before_create method &#8220;assign_additional_data&#8221; where I look up the CategoryType using the passed id.  This is so that it&#8217;s possible to raise an error if that CategoryType has been deleted in the short interval between form creation and submission.</p>
<pre><code>before_create :assign_additional_data
...
def assign_additional_data
  return if @data.nil?
  self.category_type = CategoryType.find(@data[:category_type])
end</code></pre>
<p>This is a long way of saying that I have a before_create call being added to the queue of callbacks.  However, BNS has one as well.  It sets the lft and rgt column values.  I was getting caught by the order that the before_create methods were queued up.  My model assigned the acts_as_nested_set before my before_create call</p>
<pre><code>class Category &lt; ActiveRecord::Base
  acts_as_nested_set :scope=&gt; :category_type
  before_create :assign_additional_data
  ...
end</code></pre>
<p>I had a clean db table and in my console I created two categories&#8230;</p>
<pre><code>&gt;&gt; c1 = Category.create({ :text =&gt; 'Satellite of Love', :data =&gt; { :category_type =&gt; 1 } } )
=&gt; #&lt;Category id: 1, parent_id: nil, lft: 1, rgt: 2, text: "Satellite of Love", category_type_id: 1&gt;
&gt;&gt; c2 = Category.create({ :text =&gt; 'Croooow', :data =&gt; { :category_type =&gt; 1 } } )
=&gt; #&lt;Category id: 1, parent_id: nil, lft: 1, rgt: 2, text: "Croooow", category_type_id: 1&gt;</code></pre>
<p>WHA?  Why didn&#8217;t the lft and rgt columns increment like they&#8217;re supposed to.  c2 is supposed to be &#8220;3&#8243; and &#8220;4&#8243; respectively, until that category is assigned as a child of another category.  I finally (after my headbashing) figured it out.  It was because I was assigning the category_type scope AFTER BNS calls it&#8217;s before_create method used to assign lft/rgt column values.</p>
<p>Snipped from better_nested_set.rb</p>
<pre><code>before_create :set_left_right
  ...
  # On creation, automatically add the new node to the right of all existing nodes in this tree.
  def set_left_right # already protected by a transaction within #create
    maxright = base_set_class.maximum(right_col_name, :conditions =&gt; scope_condition) || 0
    self[left_col_name] = maxright+1
    self[right_col_name] = maxright+2
  end</code></pre>
<p>Because my scope condition parameters weren&#8217;t being assigned until after BNS&#8217; before_create method, the scope id that needed to be set wasn&#8217;t being set.  So my sql statement called for the &#8220;maximum&#8221; part in the code above came out as&#8230;</p>
<pre><code>SELECT max(rgt) AS max_rgt FROM `categories` WHERE (categories.category_type_id IS NULL)</code></pre>
<p>See, category_type_id is NULL, not the &#8220;1&#8243; I wanted.  And because of that maxright gets assigned &#8220;0&#8243; and the lft and rgt columns are give &#8220;1&#8243; and &#8220;2&#8243;, respectively.</p>
<p>Well, let&#8217;s reverse the order in my Category model and see what happens.</p>
<pre><code>class Category &lt; ActiveRecord::Base
  before_create :assign_additional_data
  acts_as_nested_set :scope=&gt; :category_type
  ...
end</code></pre>
<p>Creating the two categories again gives us this&#8230;</p>
<pre><code>:text =&gt; 'Tom Servo', :lft =&gt; 1, :rgt =&gt; 2, :category_type_id =&gt; 1
:text =&gt; 'Croooow', :lft =&gt; 3, :rgt =&gt; 4, :category_type =&gt; 1</code></pre>
<p>Excellent!  It worked.  Let&#8217;s see what the &#8220;maximum&#8221; sql statement says&#8230;</p>
<pre><code>SELECT max(rgt) AS max_rgt FROM `categories` WHERE (categories.category_type_id = 1)</code></pre>
<p>Ahh, finally.  category_type_id  is being assigned the correct value.</p>
<p>So, if you are getting the &#8220;Impossible move, target node cannot be inside moved tree&#8221; error, check to see that if you&#8217;re using your own before_create methods, that they&#8217;re assigned before your call to acts_as_nested_set.</p>
]]></content:encoded>
			<wfw:commentRss>http://notso.silent-e.com/2008/02/14/before_create-gotcha-with-betternestedset-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

