<?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>ginger&#039;s thoughts &#187; rails</title>
	<atom:link href="http://blog.gingertech.net/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gingertech.net</link>
	<description>Silvia&#039;s blog</description>
	<lastBuildDate>Tue, 01 Nov 2011 10:53:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>MySQL, Snow Leopard and ruby</title>
		<link>http://blog.gingertech.net/2009/10/13/mysql-snow-leopard-and-ruby/</link>
		<comments>http://blog.gingertech.net/2009/10/13/mysql-snow-leopard-and-ruby/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 13:33:26 +0000</pubDate>
		<dc:creator>silvia</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[32 bit]]></category>
		<category><![CDATA[64 bit]]></category>
		<category><![CDATA[Mac OS 10.6]]></category>
		<category><![CDATA[MySQL 5.1]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[snow leopard]]></category>

		<guid isPermaLink="false">http://blog.gingertech.net/?p=639</guid>
		<description><![CDATA[I got a shiny new MacBook Pro on the weekend, yay! After months of complaining about the slowness and the heat evaporating from my old Macbook, I&#8217;m finally off to better grounds. But then there was the annoying task of setting up the machine with all the software that I&#8217;m using. MySQL and ruby turned [...]]]></description>
			<content:encoded><![CDATA[<p>I got a shiny new MacBook Pro on the weekend, yay! After months of complaining about the slowness and the heat evaporating from my old Macbook, I&#8217;m finally off to better grounds.</p>
<p>But then there was the annoying task of setting up the machine with all the software that I&#8217;m using. MySQL and ruby turned out to be particular problems. I installed <a href="http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg">MySQL for 10.5</a>, since MySQL haven&#8217;t published one for OS 10.6 yet. I ran &#8220;gem install mysql&#8221;. And then the pain started.</p>
<p>I got all the errors that were reported elsewhere:<br />
&#8220;<a href="http://www.ruby-forum.com/topic/192550">uninitialized constant MysqlCompat::MysqlRes</a>&#8221; and &#8220;<a href="http://forums.mysql.com/read.php?116,257419,257419">undefined method `real_connect&#8217; for Mysql:Class (NoMethodError)</a>&#8220;. I tried all the suggestions &#8211; including:<br />
<code>"sudo env ARCHFLAGS="-arch x86" gem install mysql -- --with-mysql-config=/usr/local/mysql-5.1.39-osx10.5-x86/bin/mysql_config -V --debug</code>, but just couldn&#8217;t get there.</p>
<p>My laptop reports in the System Software Overview: &#8220;64-bit Kernel and Extensions:	No&#8221;, so I assumed I had to use the 32 bit versions. However, that was a wrong assumption. Even though my kernel seems to be 32 bit, applications seem to be 64 bit.</p>
<p>So, eventually I re-installed <a href="http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.39-osx10.5-x86_64.dmg/from/http://mysql.mirrors.ilisys.com.au/">MySQL for Mac OS X 10.5 (x86_64)</a> and ran the correct gem install command:<br />
<code>sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql-5.1.39-osx10.5-x86</code> and things were fine.</p>
<p>Additionally, there was some fighting with the PrefPane and re-starting mysql. I had to kill it manually and I had to install the updated <a href="http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard#comment-25712">PrefPane of Swoon dot net</a> to make it work.</p>
<p>Hope this helps somebody avoid the same pain!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gingertech.net/2009/10/13/mysql-snow-leopard-and-ruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Date &amp; Time selection plugins for Rails</title>
		<link>http://blog.gingertech.net/2008/07/17/date-time-selection-plugins-for-rails/</link>
		<comments>http://blog.gingertech.net/2008/07/17/date-time-selection-plugins-for-rails/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 10:15:10 +0000</pubDate>
		<dc:creator>silvia</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[date plugin]]></category>

		<guid isPermaLink="false">http://blog.gingertech.net/?p=156</guid>
		<description><![CDATA[I just tried comparing the different date &#038; time selection plugins that are available for Rails and because the wiki page at rubyonrails.org is dated and I cannot edit it, I decided to write this brief blog post to save you the 20 min it took me to locate the currently available plugins and their [...]]]></description>
			<content:encoded><![CDATA[<p>I just tried comparing the different date &#038; time selection plugins that are available for Rails and because the <a href="http://wiki.rubyonrails.org/rails/pages/DatePicker">wiki page at rubyonrails.org</a> is dated and I cannot edit it, I decided to write this brief blog post to save you the 20 min it took me to locate the currently available plugins and their demos:</p>
<ul>
<li><a href="http://code.google.com/p/calendardateselect/">CalendarDateSelect</a> plugin (20k JS): <a href="http://www.restatesman.com/static/calendar">demo</a> &#8211; has different colours, small, time selection</li>
<li><a href="http://code.google.com/p/rails-unobtrusive-date-picker/">Unobtrusive JavaScript date-picker</a> plugin (80k JS): <a href="http://www.frequency-decoder.com/demo/date-picker-v2/">demo</a> &#8211; keyboard control, flexible date selection, i18n</li>
<li><a href="http://www.oreillynet.com/ruby/blog/2006/09/datebocks_the_new_intuitive_da.html">Datetime Toolbooks</a> engine (85k JS): <a href="http://datetime.toolbocks.com/">demo</a> &#8211; uses engines plugin, not very pretty, nice built-in drop-down menus, introduces date grammar</li>
<li><a href="http://dry.4thebusiness.com/?section=2">DHTML Calendar</a> plugin (76k JS): <a href="http://www.dynarch.com/projects/calendar/">demo</a> &#8211; flexible parameters to make it popup or selectable</li>
</ul>
<p>So now you can compare and pick the one that suits you best. Enjoy! <img src='http://blog.gingertech.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>UPDATE: John just told me that there is a list of other plugins at the bottom of the <a href="http://code.google.com/p/calendardateselect/">CalendarDateSelect</a> plugin page &#8211; doh!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gingertech.net/2008/07/17/date-time-selection-plugins-for-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>to_bool rails plugin</title>
		<link>http://blog.gingertech.net/2008/06/29/to_bool-rails-plugin/</link>
		<comments>http://blog.gingertech.net/2008/06/29/to_bool-rails-plugin/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 15:00:58 +0000</pubDate>
		<dc:creator>silvia</dc:creator>
				<category><![CDATA[analytics]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[FOMS]]></category>
		<category><![CDATA[LCA]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails boolean conversion]]></category>

		<guid isPermaLink="false">http://blog.gingertech.net/?p=152</guid>
		<description><![CDATA[In our rail application we do a lot of string conversions to other data types, including Boolean. Unfortunately, ruby does not provide a conversion method to_bool (which I find rather strange, to be honest). Based a blog post by Chris Roos in October 2006, we developed a rails plugin that enables the &#8220;to_bool&#8221; conversion. &#8220;to_bool&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>In our rail application we do a lot of string conversions to other data types, including Boolean. Unfortunately, ruby does not provide a conversion method to_bool (which I find rather strange, to be honest).</p>
<p>Based a <a href="http://blog.seagul.co.uk/articles/2006/10/20/boolean-method-in-ruby-sibling-of-array-float-integer-and-string">blog post by Chris Roos in October 2006</a>, we developed a rails plugin that enables the &#8220;to_bool&#8221; conversion.</p>
<p>&#8220;to_bool&#8221; works on the strings &#8220;true&#8221; and &#8220;false&#8221; and any capitalisation of these, and on numbers, as well as on nil. Other strings raise an ArgumentError.</p>
<p>Examples are as follows:</p>
<p><code>'true'.to_bool #-> true<br />
'TrUe'.to_bool #-> true<br />
true.to_bool #-> true<br />
1.to_bool #-> true<br />
5.to_bool #-> true<br />
-9.to_bool #-> true<br />
nil.to_bool #-> false<br />
'false'.to_bool #-> false<br />
'FaLsE'.to_bool #-> false<br />
false.to_bool #-> false<br />
0.to_bool #-> false<br />
</code><br />
You can find <a href='http://blog.gingertech.net/wp-content/uploads/2008/06/to_bool.tgz'>the plugin here as a tarball</a>. To install it, simply decompress the to_bool directory into your vendor/plugins directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gingertech.net/2008/06/29/to_bool-rails-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Authorization Plugin</title>
		<link>http://blog.gingertech.net/2008/05/21/rails-authorization-plugin/</link>
		<comments>http://blog.gingertech.net/2008/05/21/rails-authorization-plugin/#comments</comments>
		<pubDate>Tue, 20 May 2008 14:18:29 +0000</pubDate>
		<dc:creator>silvia</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[authorization plugin]]></category>

		<guid isPermaLink="false">http://blog.gingertech.net/2008/05/21/rails-authorization-plugin/</guid>
		<description><![CDATA[The Rails authorization plugin is a really nice way of providing role management and restrict access to specific features. It also works nicely with the RESTful authentication plugin which manages user login and authentication. However, there is a serious lack of documentation of how to use this plugin &#8211; the README.txt inside the plugin and [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://code.google.com/p/rails-authorization-plugin/">Rails authorization plugin</a> is a really nice way of providing role management and restrict access to specific features. It also works nicely with the <a href="http://agilewebdevelopment.com/plugins/restful_authentication">RESTful authentication plugin</a> which manages user login and authentication.</p>
<p>However, there is a serious lack of documentation of how to use this plugin &#8211; the README.txt inside the plugin and the source code is the best I have found. I also learnt some from the <a href="http://www.writertopia.com/dev/metaprogramming_writertopia.pdf">slides for the Railsconf 2006 on &#8220;Metaprogramming Writertopia&#8221;</a>. This blog entry is collecting what I have learnt and also freely copies some text from the different sources.</p>
<p>Assuming you have <a href="http://code.google.com/p/rails-authorization-plugin/wiki/HowToPluginInstallation">installed</a> the authorization plugin, you need to extend your <strong>models</strong> with the plugin. In particular the User model and the model(s) that you would like to use multiple user roles for.</p>
<p><code><br />
class User < ActiveRecord::Base<br />
  # Authorization plugin<br />
  acts_as_authorized_user<br />
  ...<br />
end<br />
</code></p>
<p><code><br />
class Account < ActiveRecord::Base<br />
  # Authorization plugin<br />
  acts_as_authorizable<br />
  ...<br />
end<br />
</code></p>
<p>The acts_as_authorized_user part of the plugin creates the following methods for the User model:</p>
<ul>
<li>has_role? role_name [, authorizable_obj]: finds out if a user has a certain role (for a certain object)</li>
<li>has_role role_name [, authorizable_obj]: creates the role if non-existant, and assigns the role to the user (for a certain object)</li>
<li>has_no_role role_name [, authorizable_obj]: remove role from user (for a certain object), and the role if not in use any longer</li>
</ul>
<p>As some background information, the plugin creates 2 tables - one for the roles (name, authorizable_type, authorizable_id, timestamps), and one that maps roles to users roles_users (user_id, role_id, timestamps). The authorizable_type and authorizable_id map the role to the authorizable_obj.</p>
<p>The acts_as_authorizable part of the plugin creates the following methods for the Account model:</p>
<ul>
<li>accepts_role? role_name, user: finds out if the user has the role on the model</li>
<li>accepts_role role_name, user: sets the user to have the role on the model</li>
<li>accepts_no_role role_name, user: removes the user from having the role on the model</li>
</ul>
<p>In the code, you can now use the following methods to create roles for users and accounts. Assuming we have a user 'u' and an account 'a', we can do one of the following to create the role 'admin':</p>
<ul>
<li>u.has_role 'admin', a</li>
<li>a.accepts_role 'admin', u</li>
<li>u.is_admin_for a</li>
<li>u.is_admin (gives user the role 'admin', not tied to a class or object)</li>
</ul>
<p>To check on roles, you can use the following:</p>
<ul>
<li>u.has_role 'admin', a: return true/false if the user has the role 'admin' on the account</li>
<li>u.is_admin? a: return true/false if the user has the role 'admin' on the account</li>
<li>u.is_admin_of? a: return true/false if the user has the role 'admin' on the account</li>
<li>u.has_role 'admin': return true/false if the user has the role 'admin' on anything</li>
<li>u.is_admin?: return true/false if the user has the role 'admin' on anything</li>
<li>u.is_admin_of_what Account: returns array of objects for which this user is a 'admin' (only 'Account' type)</li>
<li>u.is_admin_of_what: returns array of objects for which this user is a 'admin' (any type)</li>
<li>a.accepts_role? 'admin', u: return true/false if the account has the user with the role 'admin'</li>
<li>a.has_admin(s)?: return true/false if the account has users with the role 'admin'</li>
<li>a.has_admin(s): returns array of users which have role 'admin' on the account</li>
</ul>
<p>There are more dynamically generated methods and they are created through the method_missing hook. There is a whole domain-specific language behind this creation of methods. Just about everything that sounds like proper English will work.</p>
<p>An interesting twist is that roles can also be set on model classes: <code>u.has_role 'admin', Account</code>. So, roles can be set on one of the following three scopes:</p>
<ul>
<li>entire application (no class or object specified)</li>
<li>model class</li>
<li>an instance of a model (i.e., a model object)</li>
</ul>
<p>In your <strong>controller</strong>, you can now use two methods to check authorization at the class, instance, or instance method level: permit and permit?. permit and permit? take an authorization expression and a hash of options that typically includes any objects that need to be queried:</p>
<p><code><br />
  def index<br />
    if current_user.permit? 'site_admin'<br />
      # show all accounts<br />
      @account = Account.find(:all)<br />
    else<br />
      @account = current_user.is_admin_for_what(Account)<br />
    end<br />
  end<br />
</code></p>
<p><code><br />
class AccountController < ApplicationController<br />
  permit "site_admin and admin", :except => public_page<br />
  ...<br />
  def secret_info<br />
    permit "site_admin" do<br />
      render :text => "The Answer = 42"<br />
    end<br />
  end<br />
end<br />
</code></p>
<p>The difference between permit and permit? is redirection.</p>
<p>permit is a declarative statement and redirects by default. It can also be used as a class or an instance method, gating the access to an entire controller in a before_filter fashion. permit? is only an instance method, that can be used within expressions. It does not redirect by default. You will find more information on the boolean expression of the permit or permit? methods <a href="http://www.billkatz.com/authorization">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gingertech.net/2008/05/21/rails-authorization-plugin/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Sexier new Vquence player</title>
		<link>http://blog.gingertech.net/2008/02/14/sexier-new-vquence-player/</link>
		<comments>http://blog.gingertech.net/2008/02/14/sexier-new-vquence-player/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 08:30:06 +0000</pubDate>
		<dc:creator>silvia</dc:creator>
				<category><![CDATA[Digital Media]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[vquence]]></category>

		<guid isPermaLink="false">http://blog.gingertech.net/?p=55</guid>
		<description><![CDATA[I&#8217;ve been meaning to write about this for a while, but haven&#8217;t found a good motivation yet. Today I stumbled across the videos from RailsConf2007 on Blip.tv and decided &#8211; this is it! I will show off the nice new sexy layout of the Vquence player with this content &#8211; after all, we are a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been meaning to write about this for a while, but haven&#8217;t found a good motivation yet. Today I stumbled across the videos from RailsConf2007 on Blip.tv and decided &#8211; this is it! I will show off the nice new sexy layout of the Vquence player with this content &#8211; after all, we are a rails shop (apart from all those other programming languages that we use).</p>
<p><object align="center" type="application/x-shockwave-flash" id="vquence_swfOb" width="425" height="350" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ><param name="quality" value="high"><param name="allowScriptAccess" value="always"><param name="allowNetworking" value="all"><param name="allowFullScreen" value="true"><param name="swliveconnect" value="true"><param name="movie" value="http://static.vqslices.com/flash/videoPlayer.swf"><param name="bgcolor" value="#ffffff"><param name="flashvars" value="js_clickThrough=0&#038;js_onLoadXML=0&#038;js_onPlay=0&#038;js_playClipExternal=0&#038;autoplay=0&#038;playlist=http://www.vqslices.com/widget/2threads/authors/bLa_iU2Pur3jHcaby-aaea/videos_feed/page"><embed align="center" quality="high" allowScriptAccess="always" allowNetworking="all" pluginspage="http://www.adobe.com/go/getflashplayer" allowFullScreen="true" swliveconnect="true" src="http://static.vqslices.com/flash/videoPlayer.swf" id="vquence_swf" width="425" height="350" bgcolor="#ffffff" flashvars="js_clickThrough=0&#038;js_onLoadXML=0&#038;js_onPlay=0&#038;js_playClipExternal=0&#038;autoplay=0&#038;playlist=http://www.vqslices.com/widget/2threads/authors/bLa_iU2Pur3jHcaby-aaea/videos_feed/page" type="application/x-shockwave-flash" ></embed></object></p>
<p>Julian has worked over the design of the player in December and done an awesome job. The image pane&#8217;s scroll slows down as your reach the left or right border. It works similar to a scrollbar, where if you go to the middle of the image pane, it will scroll to the middle clip in the playlist. As you leave the image pane, it snaps back to focus on the clip that you are currently watching.</p>
<p>The new player also has a lot more text in it. As you mouse over the images, you get the titles of the clips. As you click on the (i) button, you get the annotations of the current clip (click (i) again to make it go away). At the beginning of each clip, there&#8217;s a small text reminder at the top that a click on the video will take you to the full video.</p>
<p>And finally &#8211; to give the video more space, the transport bar actually disappears as you keep watching and stop interacting with the player. This gives it more of a sit-back experience. The possibility to activate the full-screen display also adds to this experience.</p>
<p>Overall, I am really thrilled how far we have taken the player. Enjoy!</p>
<p>(But should you have any feedback or suggestions for improvement, feel free to shoot me an email or leave a comment.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gingertech.net/2008/02/14/sexier-new-vquence-player/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails and plugins</title>
		<link>http://blog.gingertech.net/2007/04/09/rails-and-plugins/</link>
		<comments>http://blog.gingertech.net/2007/04/09/rails-and-plugins/#comments</comments>
		<pubDate>Mon, 09 Apr 2007 08:40:04 +0000</pubDate>
		<dc:creator>silvia</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[vquence]]></category>

		<guid isPermaLink="false">http://blog.gingertech.net/?p=23</guid>
		<description><![CDATA[I&#8217;ve come to really love working with Ruby on Rails &#8211; it forces a structured approach of Web development upon you which helps enough to get you organised, but doesn&#8217;t get in the way of being productive. I&#8217;ve also learnt to search for plugins or gems whenever I need a specific functionality because more often [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve come to really love working with Ruby on Rails &#8211; it forces a structured approach of Web development upon you which helps enough to get you organised, but doesn&#8217;t get in the way of being productive.</p>
<p>I&#8217;ve also learnt to search for plugins or gems whenever I need a specific functionality because more often than not somebody has already solved the problem that I am trying to address.</p>
<p>Today I played with Andy Singleton&#8217;s <a href="http://wiki.rubyonrails.com/rails/pages/Uses+Guid+Plugin">GUID plugin</a> (global unique identifier) and found a bug. I haven&#8217;t found a way to publish the solution through  the rails wiki (I&#8217;m really new to the community), so I&#8217;m posting it here. I&#8217;ve also sent Andy an email, so hopefully the issue will get addressed.</p>
<p>Here is what happend.</p>
<p>I got the plugin working on my development computer and wanted to test it on another machine. However, the plugin gave me the following error message:<br />
<code><br />
#{RAILS_ROOT}/vendor/plugins/guid/lib/uuidtools.rb:235:in `timestamp_create'<br />
#{RAILS_ROOT}/vendor/plugins/guid/lib/uuidtools.rb:225:in `timestamp_create'<br />
#{RAILS_ROOT}/vendor/plugins/guid/lib/usesguid.rb:25:in `after_initialize'<br />
</code></p>
<p>After some digging I found that it uses the MAC address of the computer for seeding the GUID. To query the MAC address, it calls ifconfig (or ipconfig on a Windows machine) &#8211; which is fair enough. It has several cases that it goes through. However, the case of my machine was missing and the code did not address a nil return from the get_mac_address function.</p>
<p>My case was simple to solve: my MAC address comes in upper case characters, while the code only tested for lower-case characters. So, I added another parsing condition for my case:<br />
<code><br />
        if mac_addresses.size == 0<br />
          ifconfig_output = `/sbin/ifconfig | grep HWaddr | cut -c39-`<br />
          mac_addresses = ifconfig_output.scan(<br />
            Regexp.new("(#{(["[0-9A-F]{2}"] * 6).join(":")})"))<br />
        end<br />
</code></p>
<p>The generic problem is harder to solve &#8211; and maybe it should not be solved, but fail on the programmer, since he/she is trying to roll out GUID calculation on a machine where the program is unable to calculate a MAC address&#8230;..</p>
<p>Hmmm&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.gingertech.net/2007/04/09/rails-and-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

