<?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>Webdevotion.be &#187; Ruby On Rails</title>
	<atom:link href="http://www.webdevotion.be/blog/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevotion.be/blog</link>
	<description>Trainer for the Flash Platform and iOS</description>
	<lastBuildDate>Tue, 01 Nov 2011 10:14:44 +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>Change a column type when using Postgresql in Rails migrations</title>
		<link>http://www.webdevotion.be/blog/2010/06/16/change-a-column-type-when-using-postgresql-in-rails-migrations/</link>
		<comments>http://www.webdevotion.be/blog/2010/06/16/change-a-column-type-when-using-postgresql-in-rails-migrations/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 15:32:23 +0000</pubDate>
		<dc:creator>Webdevotion</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[:boolean]]></category>
		<category><![CDATA[:text]]></category>
		<category><![CDATA[change_column]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[migration]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://webdevotion.be/blog/?p=334</guid>
		<description><![CDATA[When using Rails, you're using migrations a lot.  Migrations are awesome.  But today I ran into a problem.  I had to convert a column to be of type :boolean ( it was of type :text ).  I was suprised when things went wrong. <a href="http://www.webdevotion.be/blog/2010/06/16/change-a-column-type-when-using-postgresql-in-rails-migrations/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When using Rails, you&#8217;re using <a href="http://guides.rubyonrails.org/migrations.html">migrations</a> a lot.  Migrations are awesome.  But today I ran into a problem.  I had to convert a column to be of type :boolean ( it was of type :text ).  I was suprised when things went wrong.<br />
<span id="more-334"></span><br />
When running the migration I got this error from Postgresql:<br />
<code>cannot be cast to type "pg_catalog.bool"</code></p>
<p>Apparantly, Postgresql can&#8217;t convert a text column into a boolean, even when passing default values.  The standard way of writing the migration didn&#8217;t work:<br />
<code>change_column :projects, :status, :boolean, :default=>true</code></p>
<p>So I started googling and ended up with:<br />
<code>execute "alter table projects ALTER COLUMN status TYPE boolean USING CASE status WHEN '1' THEN true ELSE false END;"</code></p>
<p>While this line did work, there is a problem with it; it&#8217;s not agnostic.  It&#8217;s written specifically for Postgresql, but may cause issues in other environments.</p>
<p>So, the final, agnostic solution ( <a href="http://twitter.com/simonmenke">thanks Simon</a>! )  uses plain Rails code.  Basically we add a temporary column of type :boolean to store the information.  After looping over all Project records we have converted all text values to the type boolean.  Because we have all information stored in the temporary column, it&#8217;s ok to remove the existing status column and rename convert_status to status.</p>
<pre><code>class ConvertStatusToBoolean < ActiveRecord::Migration
  def self.up
    add_column :projects, :convert_status, :boolean, :default => true

    # look up the schema's to be able to re-inspect the Project model
    # http://apidock.com/rails/ActiveRecord/Base/reset_column_information/class
    Project.reset_column_information

    # loop over the collection
    Project.all.each do |p|
        p.convert_status = p.status == '1'
        p.save
    end

    # remove the older status column
    remove_column :projects, :status
    # rename the convert_status to status column
    rename_column :projects,:convert_status,:status
  end

  def self.down
    change_column :projects, :status, :text
  end
end</code></pre>
<p>Handy cheat sheet:<br />
<a href="http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations#execute">http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations#execute</a></p>
<p>Useful info on Apidock:<br />
<a href="http://apidock.com/rails/ActiveRecord/Base/reset_column_information/class">http://apidock.com/rails/ActiveRecord/Base/reset_column_information/class</a><br />
<br/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevotion.be/blog/2010/06/16/change-a-column-type-when-using-postgresql-in-rails-migrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to PUT xml to a REST interface with Basic Authentication</title>
		<link>http://www.webdevotion.be/blog/2008/12/12/how-to-put-xml-to-a-rest-interface-with-basic-authentication/</link>
		<comments>http://www.webdevotion.be/blog/2008/12/12/how-to-put-xml-to-a-rest-interface-with-basic-authentication/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 12:36:31 +0000</pubDate>
		<dc:creator>Webdevotion</dc:creator>
				<category><![CDATA[Air]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[assembla]]></category>
		<category><![CDATA[basic auth]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[httprequest]]></category>
		<category><![CDATA[httpservice]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[urlloader]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://webdevotion.be/blog/?p=220</guid>
		<description><![CDATA[Well, this thing got me going for a couple of hours before things worked out. Using HTTPService did not seem to be the way to go. Long story short: URLRequest to the rescue! // basic authentication var encoder : Base64Encoder &#8230; <a href="http://www.webdevotion.be/blog/2008/12/12/how-to-put-xml-to-a-rest-interface-with-basic-authentication/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Well, this thing got me going for a couple of hours before things worked out.  Using HTTPService did not seem to be the way to go.  Long story short: URLRequest to the rescue!</p>
<p><img src="http://webdevotion.be/blog/wp-content/xml-rest-api.jpg" alt="" title="xml-rest-api"  width="600" class="alignnone size-full wp-image-225" /></p>
<p><span id="more-220"></span><br />
<code><br />
// basic authentication<br />
var encoder : Base64Encoder = new Base64Encoder();<br />
encoder.encode(username + ":" password);<br />
// send xml<br />
var header1:URLRequestHeader = new URLRequestHeader("Content-Type", "application/xml");<br />
// authenticate<br />
var header2:URLRequestHeader = new URLRequestHeader("Authorization", "Basic " + encoder.toString());<br />
// accept xml as response<br />
var header3:URLRequestHeader = new URLRequestHeader("Accept","application/xml");</p>
<p>var request:URLRequest = new URLRequest( urlToRestAPI );<br />
// mmm, maybe not necessary = allready in the headers<br />
request.contentType = "application/xml";<br />
// push the headers in the request<br />
request.requestHeaders.push(header1);<br />
request.requestHeaders.push(header2);<br />
request.requestHeaders.push(header3);</p>
<p>// put your xml in a string: &quot;&lt;ticket&gt;&lt;summary&gt;my summary&lt;/summary&gt;&lt;/ticket&gt;&quot;<br />
// generate an XML instance from the string<br />
var xml : XML = new XML( s );<br />
// put the xml in the request instance<br />
request.data = xml;<br />
// use PUT ( could depend on the API you are using, check the docs )<br />
request.method = "PUT";<br />
// use the loader to send the request<br />
var loader : URLLoader = new URLLoader( null );<br />
// wait for the complete event to do other amazing things<br />
loader.addEventListener(Event.COMPLETE,onTicketUpdated,false,0,true);<br />
// fire in the hole!<br />
loader.load( request );<br />
// take a deep breath and wait a sec<br />
// for the complete event to be triggered<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevotion.be/blog/2008/12/12/how-to-put-xml-to-a-rest-interface-with-basic-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Usefull Rails log visualizer with Adobe Air</title>
		<link>http://www.webdevotion.be/blog/2008/09/19/usefull-rails-log-visualizer-with-adobe-air/</link>
		<comments>http://www.webdevotion.be/blog/2008/09/19/usefull-rails-log-visualizer-with-adobe-air/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 19:10:43 +0000</pubDate>
		<dc:creator>Webdevotion</dc:creator>
				<category><![CDATA[Air]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[rails ruby air flex analytics]]></category>

		<guid isPermaLink="false">http://webdevotion.be/blog/?p=138</guid>
		<description><![CDATA[Just found this potentially usefull tool to analyse your Rails logs visually. It handles drag &#8216;n drop and has some pie charts in it. Rails Log Visualizer]]></description>
			<content:encoded><![CDATA[<p>Just found this potentially usefull tool to analyse your Rails logs visually.  It handles drag &#8216;n drop and has some pie charts in it.</p>
<p><a href="http://webdevotion.be/blog/wp-content/railslog.jpg"><img src="http://webdevotion.be/blog/wp-content/railslog-300x233.jpg" alt="" title="railslog" width="300" height="233" class="alignnone size-medium wp-image-139" /></a></p>
<p><a href="http://myspyder.net/tools/railslogvisualizer/">Rails Log Visualizer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevotion.be/blog/2008/09/19/usefull-rails-log-visualizer-with-adobe-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lib Tip: Deploying Rails Applications</title>
		<link>http://www.webdevotion.be/blog/2008/07/22/lib-tip-deploying-rails-applications/</link>
		<comments>http://www.webdevotion.be/blog/2008/07/22/lib-tip-deploying-rails-applications/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 16:32:25 +0000</pubDate>
		<dc:creator>Webdevotion</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://webdevotion.be/blog/?p=47</guid>
		<description><![CDATA[This is an amazing book. Not only does it handle what it says on the cover, but it also touches advanced use of SVN, common security issues with Rails and so on. 5 out of 5 stars!]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/Deploying-Rails-Applications-Step-Step/dp/0978739205"><img src="http://ecx.images-amazon.com/images/I/41EvmDkfJbL._SL500_AA240_.jpg"></a></p>
<p><a href="http://www.amazon.com/Deploying-Rails-Applications-Step-Step/dp/0978739205">This</a> is an amazing book.  Not only does it handle what it says on the cover, but it also touches advanced use of SVN, common security issues with Rails and so on.  5 out of 5 stars!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevotion.be/blog/2008/07/22/lib-tip-deploying-rails-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails howto: custom value field in collection_select</title>
		<link>http://www.webdevotion.be/blog/2007/11/10/rails-howto-custom-value-field-in-collection_select/</link>
		<comments>http://www.webdevotion.be/blog/2007/11/10/rails-howto-custom-value-field-in-collection_select/#comments</comments>
		<pubDate>Sat, 10 Nov 2007 14:23:27 +0000</pubDate>
		<dc:creator>Webdevotion</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://webdevotion.be/blog/?p=24</guid>
		<description><![CDATA[Very easy this one: Contact.rb ( Model ) ... def name_and_company @name_and_company = name + " - " + contact.company.name end ... Usage ( note the use of :name_and_company )]]></description>
			<content:encoded><![CDATA[<p>Very easy this one:</p>
<p><b>Contact.rb ( Model )</b><br />
<code><br />
...<br />
def name_and_company<br />
   @name_and_company = name + " - " + contact.company.name<br />
end<br />
...<br />
</code></p>
<p><b>Usage</b> ( note the use of :name_and_company )<br />
<code><br />
   <%= form.collection_select(:contact_id, @contacts, :id, :name_and_company ) %><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevotion.be/blog/2007/11/10/rails-howto-custom-value-field-in-collection_select/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The story of compound keys</title>
		<link>http://www.webdevotion.be/blog/2007/09/28/the-story-of-compound-keys/</link>
		<comments>http://www.webdevotion.be/blog/2007/09/28/the-story-of-compound-keys/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 09:37:05 +0000</pubDate>
		<dc:creator>Webdevotion</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby On Rails]]></category>

		<guid isPermaLink="false">http://webdevotion.be/blog/?p=17</guid>
		<description><![CDATA[Short story: I needed a table that could visualize the relation between two other tables ( services &#038; portfolio ). So I set up a &#8220;join table&#8221;; a table that has two columns: service_id and portfolio_id. Each column contains a &#8230; <a href="http://www.webdevotion.be/blog/2007/09/28/the-story-of-compound-keys/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Short story: I needed a table that could visualize the relation between two other tables ( services &#038; portfolio ).  So I set up a &#8220;join table&#8221;; a table that has two columns: service_id and portfolio_id.  Each column contains a foreign key ( services.id and portfolio.id ).</p>
<p>Now, what you normally do is add a third column &#8220;id&#8221; as primary key.  But in this case it can be a recipe for ( a programmer&#8217;s ) disaster. The column id would always contain a unique value, but the combination of the two other columns service_id and portfolio_id will not be unique.  And thus you could run into a situation where you have multiple rows that hold the same relation:</p>
<p><span id="more-17"></span><br />
<code><br />
id   |   service_id   | portfolio_id<br />
-------------------------------<br />
1    |         5        |       3<br />
2    |         2        |       1<br />
3    |         5        |       3<br />
</code></p>
<p>The solution is the use of a compound key: use only two columns and make them both primary key.  This will force the relation to be unique, always.  </p>
<p><code><br />
  service_id  | portfolio_id<br />
--------------------------<br />
        5        |       3<br />
        2        |       1<br />
</code></p>
<p>I&#8217;m suprised I never had to use this before, but I remembered a reference in the &#8220;Agile Development with Rails&#8221; book.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevotion.be/blog/2007/09/28/the-story-of-compound-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NetBeans 6.0 bèta ( with Ruby on Rails support! )</title>
		<link>http://www.webdevotion.be/blog/2007/09/19/sun-releases-netbeans-60-beta-with-ruby-on-rails-support/</link>
		<comments>http://www.webdevotion.be/blog/2007/09/19/sun-releases-netbeans-60-beta-with-ruby-on-rails-support/#comments</comments>
		<pubDate>Wed, 19 Sep 2007 06:12:23 +0000</pubDate>
		<dc:creator>Webdevotion</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://webdevotion.be/blog/?p=6</guid>
		<description><![CDATA[Title says it all Another one to add to the pile that is &#8220;Ruby on Rails editors&#8221;. Netbeans 6.0 bèta pages]]></description>
			<content:encoded><![CDATA[<p>Title says it all <img src='http://www.webdevotion.be/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Another one to add to the pile that is &#8220;Ruby on Rails editors&#8221;.<br />
<a href="http://www.netbeans.org/community/releases/60/index.html">Netbeans 6.0 bèta pages</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevotion.be/blog/2007/09/19/sun-releases-netbeans-60-beta-with-ruby-on-rails-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

