<?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>Transcending Frontiers &#187; Learn Ruby with the Ruby Koans</title>
	<atom:link href="http://blog.thefrontiergroup.com.au/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thefrontiergroup.com.au</link>
	<description>Your peek inside the collective mind of The Frontier Group</description>
	<lastBuildDate>Tue, 03 Jan 2012 06:53:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Learn Ruby with the Ruby Koans</title>
		<link>http://blog.thefrontiergroup.com.au/2011/10/learn-ruby-with-the-ruby-koans/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/10/learn-ruby-with-the-ruby-koans/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 06:42:59 +0000</pubDate>
		<dc:creator>mlambie</dc:creator>
				<category><![CDATA[Agile Development]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Websites or Tools]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1837</guid>
		<description><![CDATA[If you&#8217;re looking for an engaging and interactive way to learn Ruby, I&#8217;d recommend Ruby Koans by EdgeCase. I think that the koans are especially interesting if you&#8217;re coming from another programming language like PHP or Java, because they rely on some basic programming knowledge, but don&#8217;t presume any Ruby-specific abilities. The Koans walk you [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re looking for an engaging and interactive way to learn Ruby, I&#8217;d recommend <a title="Ruby Koans" href="http://rubykoans.com/">Ruby Koans</a> by <a title="EdgeCase" href="http://edgecase.com/">EdgeCase</a>. I think that the koans are especially interesting if you&#8217;re coming from another programming language like PHP or Java, because they rely on some basic programming knowledge, but don&#8217;t presume any Ruby-specific abilities.</p>
<blockquote><p>The Koans walk you along the path to enlightenment in order to learn Ruby. The goal is to learn the Ruby language, syntax, structure, and some common functions and libraries.</p></blockquote>
<p>By manipulating and building upon Ruby&#8217;s TestUnit framework, the EdgeCase developers have created a step-by-step process for teaching Ruby through the practice of &#8220;<a title="Red, Green, Refactor" href="http://jamesshore.com/Blog/Red-Green-Refactor.html">Red, Green, Refactor.</a>&#8221; They&#8217;ve added some simple game mechanics too, by showing your systematic progression through the 270+ challenges (puzzles). Reaching enlightenment results in a pretty ASCII graphic, and a legitimate sense of achievement.</p>
<p>Before you start with the koans though you&#8217;ll need a working Ruby installation. I recommend you take a look at the excellent <a title="rvm" href="http://beginrescueend.com/">rvm</a> project, which will allow you to install multiple rubies (1.8.7 and 1.9.2 for example, alongside each other) and multiple gemsets in your home directory. Former Frontiersmen and 2011 Ruby Hero Award winner <a href="http://twitter.com/#!/sutto">Darcy Laycock</a> was heavily involved in this project as part of the 2010 Ruby Summer of Code, so we really like rvm at TFG.</p>
<p>The <a href="https://github.com/edgecase/ruby_koans">GitHub repository</a> even includes a handy Keynote presentation, which I used as the basis for my talk about Ruby Koans at last week&#8217;s <a title="Ruby on Rails Perth Meetup" href="http://www.perthrubyonrails.com.au/">Ruby on Rails Oceania Perth meetup</a>.</p>
<p>Lastly, if you&#8217;d like to have a play with the koans before diving in too deep, they&#8217;re available online through your web browser at <a title="Ruby Koans Online" href="http://koans.heroku.com/">Ruby Koans Online</a>. This is a no-risk way of trying out Ruby (hint: team them up with why&#8217;s <a title="Try Ruby" href="http://tryruby.org/">Try Ruby</a> project) in your browser.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/10/learn-ruby-with-the-ruby-koans/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/10/learn-ruby-with-the-ruby-koans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing Has Face for Rails</title>
		<link>http://blog.thefrontiergroup.com.au/2011/07/introducing-has-face-for-rails/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/07/introducing-has-face-for-rails/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 01:49:17 +0000</pubDate>
		<dc:creator>Mario Visic</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1742</guid>
		<description><![CDATA[Have you ever created an application where users are trusted to upload their own avatars? Wouldn&#8217;t it be great if there was an easy way to ensure the avatar contains a person&#8217;s face? Has Face is a neat little gem that uses the face.com API to ensure that an image contains a persons face. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever created an application where users are trusted to upload their own avatars? Wouldn&#8217;t it be great if there was an easy way to ensure the avatar contains a person&#8217;s face?</p>
<p><a href="https://github.com/mariovisic/has_face">Has Face</a> is a neat little gem that uses the <a href="http://face.com">face.com API</a> to ensure that an image contains a persons face. It&#8217;s very simple to use and can be easily integrated into an existing rails application.</p>
<p>To get started add the has_face gem to your Gemfile and run a bundle install
<p class="gist-block" data-gist-id="1103591" data-gist-file="Gemfile" id="gist-1103591">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/1103591">View it on Github!</a></p>
<p>Run the generator to copy over an initializer: </p>
<p class="gist-block" data-gist-id="1103591" data-gist-file="install" id="gist-1103591">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/1103591">View it on Github!</a></p>
<p>The initializer should look something like this:</p>
<p class="gist-block" data-gist-id="1103591" data-gist-file="initializer.rb" id="gist-1103591">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/1103591">View it on Github!</a></p>
<p>Now we&#8217;ll need to make a face.com developer account. You can <a href="http://developers.face.com/signup/?g">signup for a free account over at face.com</a>. Once you have signed up, place your API key and API secret in the initializer config.</p>
<p>The last option in the initializer (skip_validation_on_error) will change the behavior of has_face when an error occurs. If set to true, when an error occurs a warning will be logged to the logfile with detailed information about the failure and face validation will be skipped. This can be useful if you want your application to function if the API service is not reachable. If the value is false then an exception will be raised when an API call fails, this will allow you to manually handle the exception yourself, please check the documentation for details on the errors raised.</p>
<p>Once the initializer settings are setup then we can add face validation to a model. In the example below I&#8217;m using carrierwave to attach the image to the model but other image attachment gems should also work fine (anything that correctly responds to `path` should be OK).</p>
<p class="gist-block" data-gist-id="1103591" data-gist-file="user.rb" id="gist-1103591">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/1103591">View it on Github!</a></p>
<p>That&#8217;s it, that&#8217;s all we need to have a functioning face validator. There are a few other options that I haven&#8217;t covered here in this short guide, please <a href="https://github.com/mariovisic/has_face">consult the readme</a> for more detailed information.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/07/introducing-has-face-for-rails/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/07/introducing-has-face-for-rails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple Database Export and Import With Character Encoding Conversion</title>
		<link>http://blog.thefrontiergroup.com.au/2011/05/simple-db-export-and-import-with-character-encoding-conversion/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/05/simple-db-export-and-import-with-character-encoding-conversion/#comments</comments>
		<pubDate>Wed, 25 May 2011 12:31:56 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1575</guid>
		<description><![CDATA[There is a gem called ydd that offers really simple import and export of smallish databases. It exports to YAML and then imports to whatever database Rails can connect to. After using YDD a few times I&#8217;ve found it easier to pinpoint the cause of problems that occur using taps. It doesn&#8217;t handle character encodings [...]]]></description>
			<content:encoded><![CDATA[<p>There is a gem called <a href="https://github.com/YouthTree/ydd">ydd</a> that offers really simple import and export of smallish databases. It exports to YAML and then imports to whatever database Rails can connect to. After using YDD a few times I&#8217;ve found it easier to pinpoint the cause of problems that occur using <a href="https://github.com/ricardochimal/taps">taps</a>.</p>
<p>It doesn&#8217;t handle character encodings though so I went about adding that. With the handy rchardet gem and IConv, detecting the character encoding of the incoming string and converting it to UTF-8 was pretty simple. I&#8217;ve created a <a href="https://github.com/YouthTree/ydd/pull/3">pull request</a> for the gem that will hopefully be accepted.</p>
<p>The essential code is below, and revolves mainly around the detection and conversion. Using //TRANSLIT causes IConv to try and convert the incoming character code to something that exists in the UTF8 character set, and then //IGNORE will ignore any characters that don&#8217;t exist in the UTF8 character set. Chaining //TRANSLIT and then //IGNORE will make IConv try a conversion first and then ignore anything it cannot convert.</p>
<p><script src="https://gist.github.com/990410.js?file=changes.rb"> </script></p>
<p>I used this gem after the above changes to convert about 400,000 records of text data with ASCII, windows-1252, IBM866 and other character encodings from an old SQLite installation to a new postgres database without any issues.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/05/simple-db-export-and-import-with-character-encoding-conversion/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/05/simple-db-export-and-import-with-character-encoding-conversion/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>RSpec 2.6.0 and RCov</title>
		<link>http://blog.thefrontiergroup.com.au/2011/05/rspec-2-6-0-and-rcov/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/05/rspec-2-6-0-and-rcov/#comments</comments>
		<pubDate>Thu, 19 May 2011 11:02:19 +0000</pubDate>
		<dc:creator>Mario Visic</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[rcov]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1510</guid>
		<description><![CDATA[Just upgraded to the newest RSpec (2.6.0) and found that RCov has stopped working completely? That&#8217;s what happened to me after running a bundle update. RCov refused to run, no error messages, just blank output. After looking around for a little while I found this: https://github.com/rspec/rspec-core/issues/370 In short: the new RSpec has been broken up [...]]]></description>
			<content:encoded><![CDATA[<p>Just upgraded to the newest RSpec (2.6.0) and found that RCov has stopped working completely? That&#8217;s what happened to me after running a bundle update. RCov refused to run, no error messages, just blank output.</p>
<p>After looking around for a little while I found this: <a href="https://github.com/rspec/rspec-core/issues/370">https://github.com/rspec/rspec-core/issues/370</a></p>
<p>In short: the new RSpec has been broken up into modules a tad more, the one that we require for rspec to run correctly <em>&#8216;autorun&#8217;</em> is not included by default, so to solve this simply add <em>require &#8216;rspec/autorun&#8217;</em> to the top of your spec_helper.</p>
<p class="gist-block" data-gist-id="978300" data-gist-file="spec_helper.rb" id="gist-978300">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/978300">View it on Github!</a></p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/05/rspec-2-6-0-and-rcov/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/05/rspec-2-6-0-and-rcov/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Sending Apple Push notifications in rails with Redis and apn_sender</title>
		<link>http://blog.thefrontiergroup.com.au/2011/05/sending-apple-push-notifications-in-rails-with-redis-and-apn_sender/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/05/sending-apple-push-notifications-in-rails-with-redis-and-apn_sender/#comments</comments>
		<pubDate>Wed, 11 May 2011 05:39:58 +0000</pubDate>
		<dc:creator>Mario Visic</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1363</guid>
		<description><![CDATA[Sending iOS push notifications from a Rails application is very easy to do these days, thankfully there are many great Ruby gems that can be used to handle most of the magic for you. Recently I ran into the apn_sender gem which handles sending push notifications in a really neat way. Sending push notifications directly [...]]]></description>
			<content:encoded><![CDATA[<p>Sending iOS push notifications from a Rails application is very easy to do these days, thankfully there are many great Ruby gems that can be used to handle most of the magic for you. Recently I ran into the <a href="https://github.com/kdonovan/apn_sender">apn_sender</a> gem which handles sending push notifications in a really neat way.</p>
<p>Sending push notifications directly from a Rails application can be slow and we probably don&#8217;t want to have the user waiting until the notification is sent, instead apn_sender can be setup to run a worker which is constantly connected to the apple push notification service. When there are new notifications to send, the notifications are queued up and sent through the always open connection that is maintained by the worker.</p>
<p>apn_sender uses <a href="http://redis.io/">redis</a> as a message queue to keep track of the notifications waiting to be sent, you&#8217;ll need to install it before using the gem.</p>
<p>To add apn_sender in your Rails 3 application, just add the gem to your Gemfile. We&#8217;re going to need the daemons gem too so we&#8217;ll include that as well.</p>
<p class="gist-block" data-gist-id="965976" data-gist-file="Gemfile" id="gist-965976">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965976">View it on Github!</a></p>
<p>Now we can create our daemon which we will be using for sending push notifications, this can be placed anywhere, I&#8217;ve put mine in script/apn_sender. Make sure to add execute permission to the file after creating so we can run it.</p>
<p class="gist-block" data-gist-id="965976" data-gist-file="apn_sender.rb" id="gist-965976">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965976">View it on Github!</a></p>
<p>Before the daemon can start running we&#8217;ll need to put our iOS push certificate into the application. Instructions for generating the certificates are available at the <a href="http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ProvisioningDevelopment/ProvisioningDevelopment.html#//apple_ref/doc/uid/TP40008194-CH104-SW1">Apple Developer site</a>. The certificates need to be placed inside of /config/certs and should be named <i>apn_development.pem</i> or <i>apn_production.pem</i> for production.</p>
<p>Once the certificates are in their correct locations, we can start up the daemon. The daemon does not know about the Rails environment so we need to specify this when starting it up. The daemon supports <i>start</i>, <i>stop</i> and <i>restart</i> commands. There is a verbose flag available to output more information (which can be helpful when debugging).</p>
<p class="gist-block" data-gist-id="965976" data-gist-file="start_command.bash" id="gist-965976">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965976">View it on Github!</a></p>
<p>Our application is now set up to send push notifications, this can now easily be performed by adding a new notification to the queue. The notify method on the APN class will take a push notification token and then our parameters, we can specify the alert message to show the user, whether or not we want sound as well as the number to display on the badge icon. Anything else we pass to notify will be sent as metadata in the push notification. Here&#8217;s an example of creating a notification.</p>
<p class="gist-block" data-gist-id="965976" data-gist-file="notify.rb" id="gist-965976">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965976">View it on Github!</a></p>
<p>The worker should pick up the notification within a few seconds and send it off. The apn_sender has many other features that I haven&#8217;t covered, you can view the full documentation over at <a href="https://github.com/kdonovan/apn_sender">https://github.com/kdonovan/apn_sender</a>.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/05/sending-apple-push-notifications-in-rails-with-redis-and-apn_sender/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/05/sending-apple-push-notifications-in-rails-with-redis-and-apn_sender/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Allowing Multiple Users to Use The Pivotal Tracker Gem</title>
		<link>http://blog.thefrontiergroup.com.au/2011/05/allowing-multiple-users-to-use-the-pivotal-tracker-gem/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/05/allowing-multiple-users-to-use-the-pivotal-tracker-gem/#comments</comments>
		<pubDate>Tue, 03 May 2011 07:39:52 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Pivotal Tracker]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1348</guid>
		<description><![CDATA[I&#8217;ve been using the Pivotal Tracker gem by Justin Smestad on a project to do various things but I ran into a problem using it with multiple API keys. The gem would create a single connection object and continue to mimic the user the first connection was made with, even when you&#8217;d updated the token [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using the <a href="https://github.com/jsmestad/pivotal-tracker">Pivotal Tracker gem</a> by <a href="https://github.com/jsmestad">Justin Smestad</a> on a project to do various things but I ran into a problem using it with multiple API keys. The gem would create a single connection object and continue to mimic the user the first connection was made with, even when you&#8217;d updated the token to different user&#8217;s token. The Tracker API relies on you passing your API key for access to the projects and stories your account has access to, so I had the problem that the first user to use my app would determin access for everyone using the app. Not good!</p>
<p>After checking out the project the change was pretty simple but it highlighted an issue that I&#8217;ve seen in plenty of code where caching is done too broadly. In this case the cacheing (or memoization) was performed without taking into account the variable that was sent to establish the connection in the first place. The offending method looked like this :</p>
<p class="gist-block" data-gist-id="965963" data-gist-file="multiple-users-1.rb" id="gist-965963">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965963">View it on Github!</a></p>
<p>This was set on the class and as such @connection would never be created after the first call, whether the token was reset or not. I just changed it so that the connection is cached for each @token the system uses. For us it&#8217;s a small number or users, but in a larger context of course you&#8217;d need to implement some invalidation protocols to stop the following code from (slowly) swallowing the world :</p>
<p class="gist-block" data-gist-id="965973" data-gist-file="multiple-users-2.rb" id="gist-965973">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965973">View it on Github!</a></p>
<p>NoToken is just a class inheriting from StandardError that I chucked in there, the only thing that makes the gem now work properly come afterwards. I setup a hash and then store a new connection for each new incoming token, the connection is keyed by the token in the @connections hash. All pretty simple.</p>
<p>I&#8217;ve created a <a href="https://github.com/jsmestad/pivotal-tracker/pull/29">pull request</a> that will hopefully be accepted soon, I think it fixes an unexpected problem with the gem.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/05/allowing-multiple-users-to-use-the-pivotal-tracker-gem/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/05/allowing-multiple-users-to-use-the-pivotal-tracker-gem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding additional processing support to CarrierWave</title>
		<link>http://blog.thefrontiergroup.com.au/2011/03/adding-additional-to-carrierwave/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/03/adding-additional-to-carrierwave/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 02:24:30 +0000</pubDate>
		<dc:creator>Mario Visic</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Inside TFG]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Websites or Tools]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1251</guid>
		<description><![CDATA[CarrierWave is a great gem for adding image uploading and basic processing abilities to your Rails applications. By default there is no way to set the quality of the resized images, which could be a very useful feature. One of the applications that we&#8217;re currently building has a requirement to resize and compress images to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/jnicklas/carrierwave">CarrierWave</a> is a great gem for adding image uploading and basic processing abilities to your Rails applications. By default there is no way to set the quality of the resized images, which could be a very useful feature.</p>
<p>One of the applications that we&#8217;re currently building has a requirement to resize and compress images to produce smaller file sizes, as well as stripping out any personal information that may be stored in the uploaded images.</p>
<p>Out of the box CarrierWave provides a consistent interface to process images using RMagick, MiniMagick  or ImageScience. Resizing and cropping is supported for all three image processing engines but setting the quality or removing personal data is not supported. Thankfully, CarrierWave provides an easy way to extend the default functionality so we can do more.</p>
<p>For the examples I&#8217;ll be adding extra functionality to RMagick processing. If you&#8217;re using MiniMagick or ImageScience the methods will need to be altered to work correctly. We&#8217;ll start by adding a new initializer into our application.</p>
<p class="gist-block" data-gist-id="965983" data-gist-file="carrierwave_initializer.rb" id="gist-965983">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965983">View it on Github!</a></p>
<p>You may be wondering about the fix_exif_rotation method. Well, some modern cameras always take photos upright, in portrait. When you take a photo in landscape mode the photo is actually saved as a portrait, but the photo will contain some extra orientation metadata. When we remove the embedded data in the photo this value gets removed, so as a result we need to manually rotate the photo, which is what this method does.</p>
<p>The application server will need to be restarted before the new initializer can be used. Once restarted the new filters can be used in an uploader like so:</p>
<p class="gist-block" data-gist-id="965983" data-gist-file="avatar_uploader.rb" id="gist-965983">Can&rsquo;t see this Gist? <a rel="nofollow" href="http://gist.github.com/965983">View it on Github!</a></p>
<p>That&#8217;s it! That&#8217;s all that&#8217;s needed to add extra quality and processing functionality to carrierwave.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/03/adding-additional-to-carrierwave/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/03/adding-additional-to-carrierwave/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Accessing ActiveRecord and ActiveModel Callback Chains in Rails 3</title>
		<link>http://blog.thefrontiergroup.com.au/2011/03/accessing-activerecord-and-activemodel-callback-chains-in-rails-3/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/03/accessing-activerecord-and-activemodel-callback-chains-in-rails-3/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 11:34:18 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ActiveModel]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Rails 3]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1244</guid>
		<description><![CDATA[It seems that access to the ActiveRecord callback chain has changed recently, however the documentation still contains the following : To list the methods and procs registered with a particular callback, append _callback_chain to the callback name that you wish to list and send that to your class from the Rails console. This used to [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that access to the ActiveRecord callback chain has changed recently, however the documentation still contains the following :</p>
<blockquote><p>To list the methods and procs registered with a particular callback, append _callback_chain to the callback name that you wish to list and send that to your class from the Rails console.</p></blockquote>
<p>This used to work in Rails 2.3.x and I&#8217;d used it a few times before, however trying to use it in Rails 3 gave me problems :</p>
<p><code><br />
HourEntry.before_save_callback_chain<br />
NoMethodError: undefined method `before_save_callback_chain' for #<br />
</code></p>
<p>After some digging around ActiveRecord then ActiveModel and ActiveSupport I figured I could just access the _#{type}_callbacks method and then reject and select these arrays to get what was required. This is what I came up with to get the before_save callbacks that I was interested in.</p>
<p><code><br />
HourEntry._save_callbacks.select { |callback| callback.kind.eql?(:before) }<br />
</code></p>
<p>This returns me the array of callback objects that are chained before I call save on the HourEntry model. If I want to check for a particular proc being in that chain then I can do :</p>
<p><code><br />
HourEntry._save_callbacks.select { |callback| callback.kind.eql?(:after) }.collect(&amp;:filter).include?(:archive_if_no_users)<br />
</code></p>
<p>It&#8217;s not optimal chaining a number of enumerable methods but I think it seems pretty readable.</p>
<p>I am hoping that the callback_chain methods return at some point (though I only used them sparingly) but more than that I&#8217;m hoping someone might be able to set me straight on how I&#8217;m going about getting around the callback chains on ActiveRecord and ActiveModel.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/03/accessing-activerecord-and-activemodel-callback-chains-in-rails-3/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/03/accessing-activerecord-and-activemodel-callback-chains-in-rails-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Composing Scopes On Multiple Models with Rails 3</title>
		<link>http://blog.thefrontiergroup.com.au/2011/03/composing-scopes-on-multiple-models-with-rails-3/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/03/composing-scopes-on-multiple-models-with-rails-3/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 11:30:25 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[AREL]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.thefrontiergroup.com.au/?p=1239</guid>
		<description><![CDATA[Today I had some knowledge delivered straight to the top of my dome, by Darcy. The issue was I had two models that I wanted to join and then apply scopes to. I wanted to retrieve Story objects that were joined to HourEntry objects, that were from this week. However when I tried to use [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had some knowledge delivered straight to the top of my dome, by Darcy. The issue was I had two models that I wanted to join and then apply scopes to. I wanted to retrieve Story objects that were joined to HourEntry objects, that were from this week. However when I tried to use the Time scope on the query it was attempting to call those methods on Story.</p>
<pre>ree-1.8.7-2011.02 :132 &gt; Story.joins(:hour_entries).this_week
NoMethodError: undefined method `this_week' for #</pre>
<p>The problem was that the .this_week call was being sent to Story rather than to HourEntry. Here&#8217;s where Darcy chimed in with the scoped.merge call. It went a little something like this :</p>
<pre>Story.scoped.merge HourEntry.this_week</pre>
<p>This successfully merged the scope defined by Story with the scope defined by the HourEntry.this_week call and I get all the stories that have HourEntry objects that are returned by the .this_week scope.</p>
<p>The final stage for this call was :</p>
<pre>Story.scoped.merge HourEntry.worked_on_by(user).this_week</pre>
<p>This then returns all the stories you&#8217;ve worked on this week. Add a bit of grouping/distinct and it&#8217;s done and done. The additional nice part about this is composing these scopes will allow me to do a lot more in the future, very quickly.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/03/composing-scopes-on-multiple-models-with-rails-3/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/03/composing-scopes-on-multiple-models-with-rails-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails Best Practices &#8211; Sitepoint</title>
		<link>http://blog.thefrontiergroup.com.au/2011/01/ruby-on-rails-best-practices-sitepoint/</link>
		<comments>http://blog.thefrontiergroup.com.au/2011/01/ruby-on-rails-best-practices-sitepoint/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 14:50:56 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Sitepoint]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=1174</guid>
		<description><![CDATA[The Frontier Group has just been added to the Sitepoint blogroll. First post by Darcy is live! Check it out here &#8211; Ruby on Rails Best Practices.]]></description>
			<content:encoded><![CDATA[<p>The Frontier Group has just been added to the <a title="Sitepoint" href="http://sitepoint.com">Sitepoint</a> blogroll. First post by <a title="Darcy Laycock" href="http://twitter.com/sutto">Darcy</a> is live!</p>
<p>Check it out here &#8211; <a href="http://blogs.sitepoint.com/2011/01/26/10-ruby-on-rails-best-practices/">Ruby on Rails Best Practices</a>.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2011/01/ruby-on-rails-best-practices-sitepoint/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2011/01/ruby-on-rails-best-practices-sitepoint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

