<?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>tov's Blog &#187; Ruby and Rails</title>
	<atom:link href="http://blog.nobody-is-like.me/category/ruby-and-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nobody-is-like.me</link>
	<description>Just another (geeky) WordPress weblog</description>
	<lastBuildDate>Tue, 16 Mar 2010 13:43:04 +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>Establish a 2nd database connection in Rails</title>
		<link>http://blog.nobody-is-like.me/2009/06/establish-a-2nd-database-connection-in-rails/</link>
		<comments>http://blog.nobody-is-like.me/2009/06/establish-a-2nd-database-connection-in-rails/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 15:54:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[informix]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.nobody-is-like.me/2009/06/18/establish-a-2nd-database-connection-in-rails/</guid>
		<description><![CDATA[OK, you can find some howto&#8217;s everywhere on the web but only on this site I found the complete solution: class SecondConnection &#60; ActiveRecord::Base SecondConnection.establish_connection( :adapter =&#62; &#34;informix&#34;, :host =&#62; &#34;localhost&#34;, :username =&#62; &#34;hansnase&#34;, :password =&#62; &#34;very_secret&#34;, :database =&#62; &#34;ccdb@localhost&#34; ) self.abstract_class = true end &#8220;self.abstract_class = true&#8221; makes the thing actually work. Otherwise Rails [...]]]></description>
			<content:encoded><![CDATA[<p>OK, you can find some howto&#8217;s everywhere on the web but only on <a href="http://blog.freerails.de/?p=347">this</a> site I found the complete solution:</p>
<pre class="brush: ruby;">
class SecondConnection &lt; ActiveRecord::Base

SecondConnection.establish_connection(
:adapter  =&gt; &quot;informix&quot;,
:host     =&gt; &quot;localhost&quot;,
:username =&gt; &quot;hansnase&quot;,
:password =&gt; &quot;very_secret&quot;,
:database =&gt; &quot;ccdb@localhost&quot;
)

self.abstract_class = true
end
</pre>
<p>&#8220;self.abstract_class = true&#8221; makes the thing actually work. Otherwise Rails seems to cache the database connection and does not switch back if you access any other classes but SecondConnection.</p>
<p>Yeah!</p>
<p>Later: Not so Yeah&#8230;</p>
<p>I had to establish another call to</p>
<pre class="brush: ruby;">
  ActiveRecord::Base.establish_connection
       logger.info { &quot;Establishing Base Connection&quot; }
       log_connections
</pre>
<p>I assume it&#8217;s either an Informix problem or related to the old rails version I&#8217;m driving with.<br />
Nevertheless: It works now.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobody-is-like.me/2009/06/establish-a-2nd-database-connection-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails and incoming mails on a Mac Leopard workstation</title>
		<link>http://blog.nobody-is-like.me/2009/06/rails-and-incoming-mails-on-a-mac-leopard-workstation/</link>
		<comments>http://blog.nobody-is-like.me/2009/06/rails-and-incoming-mails-on-a-mac-leopard-workstation/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 16:27:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Ruby and Rails]]></category>

		<guid isPermaLink="false">http://blog.nobody-is-like.me/2009/06/17/rails-and-incoming-mails-on-a-mac-leopard-workstation/</guid>
		<description><![CDATA[Obviously I&#8217;m in a need of such an installation, otherwise I wouldn&#8217;t have googled about this (btw.: Do you know lmgtfy.com). Here are some snippets from: ChrizDee Craig Ambrose And? What did I do: I first enabled Postfix using 1). After this I have changed /etc/aliases: echo 'rails_mailer: &#34;&#124;/usr/local/bin/mail_handler.rb&#34;' &#62;&#62; /etc/aliases chmod 755 /usr/local/bin/mail_handler.rb&#34;' &#62;&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Obviously I&#8217;m in a need of such an installation, otherwise I wouldn&#8217;t have googled about this (btw.: Do you know <a href="http://lmgtfy.com">lmgtfy.com</a>).</p>
<p>Here are some snippets from:</p>
<ol>
<li><a href="http://www.chrizdee.de/2008/10/20/postfix-mailserver-unter-os-x-leopard-einrichten/">ChrizDee</a></li>
<li><a href="http://blog.craigambrose.com/past/2008/2/9/respond_toemail_or_how_to_handle/">Craig Ambrose</a></li>
</ol>
<p>And? What did I do:</p>
<p>I first enabled Postfix using 1). After this I have changed /etc/aliases:</p>
<pre class="brush: ruby;">

echo 'rails_mailer: &quot;|/usr/local/bin/mail_handler.rb&quot;' &gt;&gt; /etc/aliases
chmod 755 /usr/local/bin/mail_handler.rb&quot;' &gt;&gt; /etc/aliases
sudo newaliases
sudo postfix reload
</pre>
<pre class="brush: ruby;">
#!/usr/bin/ruby
require 'net/http'
require 'uri'Net::HTTP.post_form URI.parse('http://localhost:3000/emails'), { &quot;email&quot; =&gt; STDIN.read }
</pre>
<p>The script above will be triggered by every mail that will be sent to rails_mailer@localhost (resp. your hostname). It will put a post-request to localhost:3000/email including the email in the parameter &#8220;email&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobody-is-like.me/2009/06/rails-and-incoming-mails-on-a-mac-leopard-workstation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ein paar Ruby-Schnipsel</title>
		<link>http://blog.nobody-is-like.me/2009/06/ein-paar-ruby-schnipsel/</link>
		<comments>http://blog.nobody-is-like.me/2009/06/ein-paar-ruby-schnipsel/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 14:13:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Ruby and Rails]]></category>

		<guid isPermaLink="false">http://blog.nobody-is-like.me/2009/06/10/ein-paar-ruby-schnipsel/</guid>
		<description><![CDATA[Ein paar Lebensretter für mich: Installation von Postgresql unter Mac OS Wenn Rubyforge down ist:  gem install &#8211;source http://rf.gems.mocra.com NAME_OF_THE_GEM Robby on Rails (Mac/Leopard/Rails etc.)]]></description>
			<content:encoded><![CDATA[<p>Ein paar Lebensretter für mich:</p>
<ul>
<li><a href="http://www.rolleyes.de/blog/2008/07/17/ruby-rails-und-postgresql-fur-mac-os-x-105/">Installation von Postgresql unter Mac OS</a></li>
<li>Wenn Rubyforge down ist:  gem install &#8211;source http://rf.gems.mocra.com NAME_OF_THE_GEM</li>
<li>Robby on Rails <a href="http://www.robbyonrails.com/articles/2008/01/22/installing-ruby-on-rails-and-postgresql-on-os-x-third-edition">(Mac/Leopard/Rails etc.)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobody-is-like.me/2009/06/ein-paar-ruby-schnipsel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hpricot: XML to Hash</title>
		<link>http://blog.nobody-is-like.me/2009/03/hpricot-xml-to-hash/</link>
		<comments>http://blog.nobody-is-like.me/2009/03/hpricot-xml-to-hash/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 18:20:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[Hpricot]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.nobody-is-like.me/?p=21</guid>
		<description><![CDATA[Well: I nearly lost all my hairs about this. Strange that I couldn&#8217;t find something like this in the docs.Situation: I have some XML code from that I need parts being put into a simple hash (see below). The following small ruby snippet does exactly this. Only thing that&#8217;s not working is the &#8220;inner_xml&#8221; part. [...]]]></description>
			<content:encoded><![CDATA[<p>Well: I nearly lost all my hairs about this. Strange that I couldn&#8217;t find something like this in the docs.Situation:</p>
<p>I have some XML code from that I need parts being put into a simple hash (see below).</p>
<p>The following small ruby snippet does exactly this.</p>
<p>Only thing that&#8217;s not working is the  &#8220;inner_xml&#8221; part. I personally don&#8217;t need it but your mileage may vary and you may want to fix the issue (and give me a note)</p>
<pre class="brush: ruby;">
require 'rubygems'
require 'hpricot'
require 'pp'

text = &lt;&lt;eof
&lt;payment&gt;
		&lt;vat&gt;
			&lt;pay_vat&gt;0&lt;/pay_vat&gt;
			&lt;vat_id/&gt;
		&lt;/vat&gt;
		&lt;creditcard&gt;
			&lt;type&gt;master&lt;/type&gt;
			&lt;holder&gt;Franz Fluchsfinger&lt;/holder&gt;
			&lt;company/&gt;
			&lt;no&gt;52660xxxxxxxxxxx79&lt;/no&gt;
			&lt;kpn/&gt;
			&lt;valid_until&gt;09/10&lt;/valid_until&gt;
			&lt;data&gt;Just some data&lt;/data&gt;
			&lt;xml_for_demo&gt;&lt;inner_xml&gt;inner text&lt;/inner_xml&gt;&lt;/xml_for_demo&gt;
			&lt;signature&gt;a5f4e2shortened4b1e523ca873837c8f1c9ea66ee1924d&lt;/signature&gt;
		&lt;/creditcard&gt;
&lt;/payment&gt;
eof

xml =Hpricot.XML(text)
a= xml/&quot;creditcard/*&quot;
h={}
a.each {|b|
	h[b.name] = b.inner_text if b.is_a? Hpricot::Elem
}
pp h	
</pre>
<p>result:</p>
<p>[code]]czozMDE6XCINCnJ1YnkgdGVzdC5yYg0Ke1wiY29tcGFueVwiPSZndDtcIlwiLA0KXCJ4bWxfZm9yX2RlbW9cIj0mZ3Q7XCJpbm5lciB0ZXh0XCIsDXtbJiomXX0KXCJub1wiPSZndDtcIjUyNjYweHh4eHh4eHh4eHg3OVwiLA0KXCJob2xkZXJcIj0mZ3Q7XCJGcmFueiBGbHVjaHNmaW5nZXJcIiwNClwic2lnbmF0e1smKiZdfXVyZVwiPSZndDtcImE1ZjRlMnNob3J0ZW5lZDRiMWU1MjNjYTg3MzgzN2M4ZjFjOWVhNjZlZTE5MjRkXCIsDQpcInR5cGVcIj0mZ3Q7XCJtYXN7WyYqJl19dGVyXCIsDQpcInZhbGlkX3VudGlsXCI9Jmd0O1wiMDkvMTBcIiwNClwia3BuXCI9Jmd0O1wiXCIsDQpcImRhdGFcIj0mZ3Q7XCJKdXN0IHNvbWUgZGF0YXtbJiomXX1cIn0NClwiO3tbJiomXX0=[[/code]</p>
<p>Btw.: I found the solution partly on <a href="http://railsforum.com/viewtopic.php?id=22055">http://railsforum.com/viewtopic.php?id=22055</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobody-is-like.me/2009/03/hpricot-xml-to-hash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Snippets &#8212; Arbitrary SQL</title>
		<link>http://blog.nobody-is-like.me/2009/02/rails-snippets-arbitrary-sql/</link>
		<comments>http://blog.nobody-is-like.me/2009/02/rails-snippets-arbitrary-sql/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 11:30:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby and Rails]]></category>

		<guid isPermaLink="false">http://blog.nobody-is-like.me/?p=20</guid>
		<description><![CDATA[Seems I&#8217;m in a Ruby/Rails mood today Sometimes you don&#8217;t need the whole Rails stuff and just want to place a query. Try the following: [code]]czo0OTpcIkFjdGl2ZVJlY29yZDo6QmFzZS5jb25uZWN0aW9uLihzZWxlY3RfYWxsfHVwZGF0ZSlcIjt7WyYqJl19[[/code] will do the trick. Example: [code]]czo3NDpcImxpc3QgPSBBY3RpdmVSZWNvcmQ6OkJhc2UuY29ubmVjdGlvbi5zZWxlY3RfYWxsKFwic2VsZWN0IGEsYiBmcm9tIGNfdGFie1smKiZdfWxlXCIpXCI7e1smKiZdfQ==[[/code] ==&#62; [ {a =&#62; Value_for_a, b =&#62; Value_for_b}, {a =&#62; Value...}...] [code]]czoxMTc6XCIgbnVtYmVyX29mX3Jvd3MgPSBBY3RpdmVSZWNvcmQ6OkJhc2UuY29ubmVjdGlvbi51cGRhdGUoXCJ1cGRhdGUgbW9udGgge1smKiZdfXNldCBtb250aF9pZCA9IG1vbnRoX2lkICsxIHdoZXJlIG1vbnRoX2lkID0gMTFcIilcIjt7WyYqJl19[[/code] If you make use of an already created Rails Model instead [...]]]></description>
			<content:encoded><![CDATA[<p>Seems I&#8217;m in a Ruby/Rails mood today</p>
<p>Sometimes you don&#8217;t need the whole Rails stuff and just want to place a query.</p>
<p>Try the following:<br />
[code]]czo0OTpcIkFjdGl2ZVJlY29yZDo6QmFzZS5jb25uZWN0aW9uLihzZWxlY3RfYWxsfHVwZGF0ZSlcIjt7WyYqJl19[[/code]<br />
will do the trick.<br />
Example:</p>
<p>[code]]czo3NDpcImxpc3QgPSBBY3RpdmVSZWNvcmQ6OkJhc2UuY29ubmVjdGlvbi5zZWxlY3RfYWxsKFwic2VsZWN0IGEsYiBmcm9tIGNfdGFie1smKiZdfWxlXCIpXCI7e1smKiZdfQ==[[/code]</p>
<p>==&gt; [ {a =&gt; Value_for_a, b =&gt; Value_for_b}, {a =&gt; Value...}...]</p>
<p>[code]]czoxMTc6XCIgbnVtYmVyX29mX3Jvd3MgPSBBY3RpdmVSZWNvcmQ6OkJhc2UuY29ubmVjdGlvbi51cGRhdGUoXCJ1cGRhdGUgbW9udGgge1smKiZdfXNldCBtb250aF9pZCA9IG1vbnRoX2lkICsxIHdoZXJlIG1vbnRoX2lkID0gMTFcIilcIjt7WyYqJl19[[/code]</p>
<p>If you make use of an already created Rails Model instead of the base class, you will get the benefit of accessors (instead of hash-keys) for the  selected objects.</p>
<p>Example (necessary, I know <img src='http://blog.nobody-is-like.me/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )</p>
<ul>
<li>create the model</li>
</ul>
<p>[code]]czozMDpcIiMgc2NyaXB0L2dlbmVyYXRlIG1vZGVsIENUYWJsZVwiO3tbJiomXX0=[[/code]</p>
<ul>
<li>use it in your code</li>
</ul>
<p>[code]]czo1MzpcIiBsaXN0ID0gQ1RhYmxlLmZpbmRfYnlfc3FsKFwic2VsZWN0IGEsYiBmcm9tIGNfdGFibGVcIilcIjt7WyYqJl19[[/code]</p>
<ul>
<li>access elements</li>
</ul>
<p>[code]]czoxMjpcInBwIGxpc3RbMF0uYVwiO3tbJiomXX0=[[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobody-is-like.me/2009/02/rails-snippets-arbitrary-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Snippets</title>
		<link>http://blog.nobody-is-like.me/2009/02/rails-snippets-2/</link>
		<comments>http://blog.nobody-is-like.me/2009/02/rails-snippets-2/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 09:43:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.nobody-is-like.me/?p=19</guid>
		<description><![CDATA[OK, this is more Ruby than Rails but nevertheless helpful&#8230; If you come from a Perl background you will be surprised that in Ruby an array is definitively not a list. So if you want to pass a list of elements to a method that you have stored in an array, you may want to [...]]]></description>
			<content:encoded><![CDATA[<p>OK, this is more Ruby than Rails but nevertheless helpful&#8230;</p>
<p>If you come from a Perl background you will be surprised that in Ruby an array is definitively not a list. So if you want to pass a list of elements to a method that you have stored in an array, you may want to use the following idiom:<br />
[code]]czoxMTU6XCJsaXN0ID0gW10NCmxpbmVzID0gRmlsZS5yZWFkbGluZXMoXCJGSUxFTkFNRVwiKQ0KbGluZXMuZWFjaCBkbyB8bGluZXwNCntbJiomXX1saXN0LnB1c2goUmVzdWx0Lm5ldygqbGluZS5zcGxpdChcIiBcIikpKQ0KZW5kDQpcIjt7WyYqJl19[[/code]<br />
The [code]]czoxNjpcIipsaW5lLnNwbGl0KFwiIFwiKVwiO3tbJiomXX0=[[/code] creates an element list out of the array that the split command has created.</p>
<p>I fear a real Rubyist would have done it in a different way but OK.</p>
<p>P.S. Does someone know what I'm doing wrong with the code formatting in WordPress? I'm quite sure to have included whitespaces in the code above...</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobody-is-like.me/2009/02/rails-snippets-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Snippets</title>
		<link>http://blog.nobody-is-like.me/2009/02/rails-snippets/</link>
		<comments>http://blog.nobody-is-like.me/2009/02/rails-snippets/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 10:27:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.nobody-is-like.me/?p=15</guid>
		<description><![CDATA[Some small snippets of Rails/Ruby codes that I&#8217;d like to not forget&#8230; I found an interesting site on the Web: http://matthall.wordpress.com/2006/12/06/how-to-execute-a-rails-controller-action-via-cron/  Tweaking it a bit: [code]]czoyMTQ6XCJyZXF1aXJlIFwnLi4vY29uZmlnL2Vudmlyb25tZW50XCcNCnJlcXVpcmUgXCdwcFwnDQppZCA9IEFSR1ZbMF0NCmlmIGlkLm5pe1smKiZdfWw/DQpyYWlzZSAmbHQ7PGVvZj4NClVTQUdFOiAkMCBSRVNFTExFUl9JRA0KZW9mDQplbmQNCmFwcCA9IEFjdGlvbkNvbnRyb2xsZXJ7WyYqJl19OjpJbnRlZ3JhdGlvbjo6U2Vzc2lvbi5uZXcNCmFwcC5nZXQgXCIva3VuZGVuL3N0YXR1c19tYWlsLyN7aWR9XCI8L2VvZj5cIjt7WyYqJl19[[/code] This works fine from a Rails subdirectory and calls the same action like http://RAILSSITE/kunden/status_mail/ID]]></description>
			<content:encoded><![CDATA[<p>Some small snippets of Rails/Ruby codes that I&#8217;d like to not forget&#8230;</p>
<p>I found an interesting site on the Web: <a href="http://matthall.wordpress.com/2006/12/06/how-to-execute-a-rails-controller-action-via-cron/" title="How to Execute a Rails Controller Action via. Cron">http://matthall.wordpress.com/2006/12/06/how-to-execute-a-rails-controller-action-via-cron/ </a></p>
<p>Tweaking it a bit:<br />
[code]]czoyMTQ6XCJyZXF1aXJlIFwnLi4vY29uZmlnL2Vudmlyb25tZW50XCcNCnJlcXVpcmUgXCdwcFwnDQppZCA9IEFSR1ZbMF0NCmlmIGlkLm5pe1smKiZdfWw/DQpyYWlzZSAmbHQ7PGVvZj4NClVTQUdFOiAkMCBSRVNFTExFUl9JRA0KZW9mDQplbmQNCmFwcCA9IEFjdGlvbkNvbnRyb2xsZXJ7WyYqJl19OjpJbnRlZ3JhdGlvbjo6U2Vzc2lvbi5uZXcNCmFwcC5nZXQgXCIva3VuZGVuL3N0YXR1c19tYWlsLyN7aWR9XCI8L2VvZj5cIjt7WyYqJl19[[/code]</p>
<p>This works fine from a Rails subdirectory and calls the same action like http://RAILSSITE/kunden/status_mail/ID</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nobody-is-like.me/2009/02/rails-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
