<?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>Roamings of a Hobbyist Ruby on Rails Developer</title>
	<atom:link href="http://www.blog.gregnet.org/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.blog.gregnet.org</link>
	<description>My running list of Rails gottcha's that got me!</description>
	<lastBuildDate>Sat, 28 Mar 2009 05:21:18 +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>capistrano gets &#8220;failed password&#8221; when accessing git repository server</title>
		<link>http://www.blog.gregnet.org/?p=39</link>
		<comments>http://www.blog.gregnet.org/?p=39#comments</comments>
		<pubDate>Sat, 14 Feb 2009 20:53:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.blog.gregnet.org/?p=39</guid>
		<description><![CDATA[Hi, This one concerns using capistrano for Rails deployment, and git for version control. I got stuck for quite some time on this. PROBLEM: I could ssh into my target prod server, and from there ssh into my repo server (for git) fine. When I run &#8220;cap deploy:update&#8221; it seems when the capistrano scripts running [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>This one concerns using <a href="http://www.capify.org/">capistrano</a> for Rails deployment,  and <a href="http://git-scm.com/">git</a> for version control.  I got stuck for quite some time on this.  </p>
<p>PROBLEM: I could ssh into my target prod server, and from there ssh into my repo server (for git) fine.   When I run &#8220;cap deploy:update&#8221; it seems when the capistrano scripts running on my target prod server get a &#8220;failed password&#8221; when trying to access the repo server.</p>
<p>After some great help from Jamis Buck (developer of capistrano) the problem became clearer.</p>
<p>ANSWER: Set the following variable in the capistrano &#8220;./config/deploy.rb&#8221; file. </p>
<pre name="code" class="ruby">
&quot;default_run_options[:pty] = true&quot;
</pre>
<p>FURTHER INFO (from Jamis)</p>
<pre name="code" class="ruby">
By default, Capistrano WILL load ~/.bashrc for each command (since
about cap 2.4 or so). However, this default causes problems with
interactive processes, like sudo or svn or other processes that may
want to prompt for input. Thus, it is common for people to tell
Capistrano to request a pty from the server, via
default_run_options[:pty] = true. However, when cap requests a pty,
the shell will not load the user&#039;s profile script.

There&#039;s no good solution for this, except to NOT rely on your .bashrc
(or similar) script. What kinds of things are you expecting to be set
that way?

You can mimic a pty-less SSH session like this:

 ssh -T host.com &quot;git clone -q /repos/equity/.git /tmp/test&quot;

Likewise, you can mimic SSH session with pty-allocation like this:

 ssh -t host.com &quot;git clone -q /repos/equity/.git /tmp/test&quot;

(pty-allocation is the default for openssh, but the difference there
is that ssh requests an interactive user shell, and capistrano does
not.)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gregnet.org/?feed=rss2&amp;p=39</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>running test coverage (rcov) and displaying results in one hit</title>
		<link>http://www.blog.gregnet.org/?p=35</link>
		<comments>http://www.blog.gregnet.org/?p=35#comments</comments>
		<pubDate>Sun, 21 Dec 2008 20:24:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rcov]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.blog.gregnet.org/?p=35</guid>
		<description><![CDATA[Reminder re how to run &#8220;rcov&#8221; for code coverage, and display the results in a browser in one hit. Solution: rake spec:rcov &#038;&#038; open coverage/index.html]]></description>
			<content:encoded><![CDATA[<p>Reminder re how to run &#8220;rcov&#8221; for code coverage, and display the results in a browser in one hit.  </p>
<p><strong>Solution: </strong><br />
<code>rake spec:rcov &#038;&#038; open coverage/index.html</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gregnet.org/?feed=rss2&amp;p=35</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>undefined method errors in test specs!  but works fine in ./script/console???</title>
		<link>http://www.blog.gregnet.org/?p=31</link>
		<comments>http://www.blog.gregnet.org/?p=31#comments</comments>
		<pubDate>Wed, 17 Dec 2008 01:36:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.blog.gregnet.org/?p=31</guid>
		<description><![CDATA[Had an issue trying to resolve the following error I was getting in one of my test specs (i.e. RSpec tests) recently: undefined method `account_item_id=' for # When I did the same thing the test spec was doing in the rails console (i.e. ./script/console) things worked fine. Couldn&#8217;t work it out. Solution: You may have [...]]]></description>
			<content:encoded><![CDATA[<p>Had an issue trying to resolve the following error I was getting in one of my test specs (i.e. RSpec tests) recently:</p>
<p><code>   undefined method `account_item_id=' for #<Allocation:0x241623c></code></p>
<p>When I did the same thing the test spec was doing in the rails console (i.e. ./script/console) things worked fine.  Couldn&#8217;t work it out.  </p>
<p><strong>Solution: </strong> You may have guessed it.   The tests work on the &#8220;test&#8221; database, not the &#8220;development&#8221; database.  I needed to run the &#8220;rake db:migrate RAILS_ENV=test&#8221; to bring my test database schema up to date.  Doh!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gregnet.org/?feed=rss2&amp;p=31</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>recursive &#8220;svn add&#8221; approach</title>
		<link>http://www.blog.gregnet.org/?p=29</link>
		<comments>http://www.blog.gregnet.org/?p=29#comments</comments>
		<pubDate>Tue, 16 Dec 2008 03:21:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://www.blog.gregnet.org/?p=29</guid>
		<description><![CDATA[Not being an SVN (subversion) guru I wanted to find a way to recursively add files (svn add) to put them under version control. Solution: Here&#8217;s the solution (updated from Paul&#8217;s suggestion below): “svn add * –force” This will recursively add new files and skip any files that are already in svn. The original solution [...]]]></description>
			<content:encoded><![CDATA[<p>Not being an SVN (subversion) guru I wanted to find a way to recursively add files (svn add) to put them under version control.  </p>
<p><strong>Solution:</strong> Here&#8217;s the solution (updated from Paul&#8217;s suggestion below):</p>
<pre name="code" class="ruby">

 “svn add * –force” This will recursively add new files and skip any files that are already in svn.
</pre>
<p>The original solution I was using was the below:</p>
<pre name="code" class="ruby">

svn status | grep &quot;^\?&quot; | awk &#039;{print $2}&#039; | xargs svn add
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gregnet.org/?feed=rss2&amp;p=29</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;save!&#8221; not working (nothing persisted to DB) but return result is &#8220;nil&#8221; rather than an error message</title>
		<link>http://www.blog.gregnet.org/?p=17</link>
		<comments>http://www.blog.gregnet.org/?p=17#comments</comments>
		<pubDate>Mon, 15 Dec 2008 05:47:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[activerecord]]></category>

		<guid isPermaLink="false">http://www.blog.gregnet.org/?p=17</guid>
		<description><![CDATA[I recently was stuck trying to work out why a &#8220;save!&#8221; on one of my models was not working. I had checked and verified that the model object was valid first. I checked the database directly and there were definitely no record being saved. Console Output Highlight the Issue &#62;&#62; a = Allocation.new =&#62; #&#60;Allocation [...]]]></description>
			<content:encoded><![CDATA[<p>I recently was stuck trying to work out why a &#8220;save!&#8221; on one of my models was not working.  I had checked and verified that the model object was valid first.   I checked the database directly and there were definitely no record being saved.  </p>
<p><strong>Console Output Highlight the Issue</strong></p>
<pre name="code" class="ruby">

&gt;&gt; a = Allocation.new
=&gt; #&lt;Allocation id: nil, transaction_id: nil, person_id: nil, recurring_id: nil, amount: nil, amount_percent: nil, created_at: nil, updated_at: nil&gt;
&gt;&gt;
?&gt; a.valid?
=&gt; false
&gt;&gt; a.amount = 1
=&gt; 1
&gt;&gt; a.transaction_id = 1
=&gt; 1
&gt;&gt; a.person_id = 1
=&gt; 1
&gt;&gt;
?&gt; a.valid?
=&gt; true
&gt;&gt;
?&gt;
?&gt; a.save
=&gt; nil
&gt;&gt; a.save!
=&gt; nil
</pre>
<p><strong>SQL Commands Observed</strong></p>
<pre name="code" class="ruby">

Transaction Columns (0.003291)   SHOW FIELDS FROM `transactions`
  Transaction Load (0.001494)   SELECT * FROM `transactions` WHERE (`transactions`.`id` = 1) 
</pre>
<p><strong>Model Code</strong></p>
<pre name="code" class="ruby">

class Allocation &lt; ActiveRecord::Base
  belongs_to :person
  belongs_to :transaction

  validates_numericality_of :amount, :if =&gt; :amount
  validates_numericality_of :amount_percent, :if =&gt; :amount_percent

  private

  def validate
    errors.add_to_base(&#039;amount and amount_percent can not both be specified&#039;) if amount &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; amount_percent
    errors.add_to_base(&#039;either amount OR amount_percent must be specified&#039;) if !amount &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; !amount_percent
  end  

end
</pre>
<p>Can you see the issue?  (I couldn&#8217;t)</p>
<p><strong>Solution:</strong>Transaction is a reserved class in Rails, and it was the name of one of my models, in this case it was one that my &#8220;Allocation&#8221; model had an association with.  The &#8220;belongs_to transaction&#8221; line was creating a &#8220;transaction&#8221; method for reading the association. This overwrote an internal method called transaction.  The internal method just runs its block inside a database transaction and is used on saves etc&#8230; By replacing that with a transaction method that does nothing with the block you completely neutre activerecord. </p>
<p>For a list of Rails reserved words see: <a href="http://wiki.rubyonrails.org/rails/pages/ReservedWords">http://wiki.rubyonrails.org/rails/pages/ReservedWords</a></p>
<p>I&#8217;ll be starting the renaming of the model &#8220;transaction&#8221; that I had shortly <img src='http://www.blog.gregnet.org/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p><strong>Acknowledgements:</strong>Ryan Bigg, Frederick Cheung and Chris Bartlett from the Rails mailing list.  Thanks guys.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gregnet.org/?feed=rss2&amp;p=17</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>viewing SQL statements when using the rails console</title>
		<link>http://www.blog.gregnet.org/?p=15</link>
		<comments>http://www.blog.gregnet.org/?p=15#comments</comments>
		<pubDate>Mon, 15 Dec 2008 05:22:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.blog.gregnet.org/?p=15</guid>
		<description><![CDATA[Ever wanted to view the SQL statements being issued to your database when you are in the Rails console (i.e. ./script/console), i.e. in development mode. I posted on the mailing list and got one way forward here. Solution: Run up a server in a separate terminal to view the SQL statements (i.e. ./script/server). They appear [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to view the SQL statements being issued to your database when you are in the Rails console (i.e. ./script/console), i.e. in development mode.  I posted on the mailing list and got one way forward here.</p>
<p><strong>Solution: </strong> Run up a server in a separate terminal to view the SQL statements (i.e. ./script/server).  They appear here fine.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gregnet.org/?feed=rss2&amp;p=15</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No such file or directory &#8211; /tmp/mysql.sock</title>
		<link>http://www.blog.gregnet.org/?p=9</link>
		<comments>http://www.blog.gregnet.org/?p=9#comments</comments>
		<pubDate>Sat, 06 Dec 2008 20:38:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[migration]]></category>

		<guid isPermaLink="false">http://www.blog.gregnet.org/?p=9</guid>
		<description><![CDATA[I spent 15 minutes recently trying to work out why I was getting this error when I was trying to run a migration on my production site: [root@home current]# rake db:migrate VERSION=production (in /u/apps/myequity/releases/20081206042650) rake aborted! No such file or directory - /tmp/mysql.sock (See full trace by running task with --trace) Do you see the [...]]]></description>
			<content:encoded><![CDATA[<p>I spent 15 minutes recently trying to work out why I was getting this error when I was trying to run a migration on my production site:</p>
<pre name="code" class="ruby">

[root@home current]# rake db:migrate VERSION=production
(in /u/apps/myequity/releases/20081206042650)
rake aborted!
No such file or directory - /tmp/mysql.sock
(See full trace by running task with --trace)
</pre>
<p>Do you see the problem?  What if I show you the db:migrate help&#8230;</p>
<pre name="code" class="ruby">

[root@home current]# rake -D db:migrate
(in /u/apps/myequity/releases/20081206042650)
rake db:migrate
    Migrate the database through scripts in db/migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false.
</pre>
<p>So basically I was using VERSION rather than RAILS_ENV (which isn&#8217;t mentioned in the description)  <img src='http://www.blog.gregnet.org/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />   Things worked fine after issuing the correct line:</p>
<pre name="code" class="ruby">

[root@home current]# rake db:migrate RAILS_ENV=production
(in /u/apps/myequity/releases/20081206042650)
[root@home current]# 
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gregnet.org/?feed=rss2&amp;p=9</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction</title>
		<link>http://www.blog.gregnet.org/?p=3</link>
		<comments>http://www.blog.gregnet.org/?p=3#comments</comments>
		<pubDate>Mon, 11 Aug 2008 01:13:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.blog.gregnet.org/?p=3</guid>
		<description><![CDATA[Hi, This blog captures the learnings of a hobbyist Ruby on Rails developer as he stumbles through the word of web development.   Hopefully someone might even learn something&#8230;]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>This blog captures the learnings of a hobbyist Ruby on Rails developer as he stumbles through the word of web development.   Hopefully someone might even learn something&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.gregnet.org/?feed=rss2&amp;p=3</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
