<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" version="2.0"><channel><title>David Jones - Home</title><link>http://www.d-jones.com/</link><language>en-US</language><lastBuildDate>Mon, 07 Jul 2008 22:59:48 -0500</lastBuildDate><generator>Mephisto Noh-Varr http://mephistoblog.com</generator><description></description><geo:lat>-43.534767</geo:lat><geo:long>172.64034</geo:long><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/djones_blog" type="application/rss+xml" /><item><title>iPhone in New Zealand: Vodafone's Greed</title><link>http://www.d-jones.com/2008/7/7/apple-iphone-new-zealand-vodafone</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Mon, 07 Jul 2008 22:59:48 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-07-07:53</guid><description>&lt;p&gt;
Vodafone just released their &lt;a href="http://www.vodafone.co.nz/iphone/plans.jsp"&gt;iPhone plans in New Zealand&lt;/a&gt; and oh boy did Vodafone screw us all!&lt;/p&gt;
&lt;p&gt;Sure it's a desired item, but NZ$1129 for a 16GB model is insane. You could almost &lt;a href="http://www.dse.co.nz/cgi-bin/dse.storefront/4872a03c07bbdabc273fc0a87f3b0727/Product/View/G2145"&gt;buy a 37" LCD TV&lt;/a&gt; for that price!
&lt;/p&gt;
&lt;p&gt;What's really insane is the prices of the plans. Their highest plan is $250/month and they still want you to pay $199 for the phone! You're going to pay them $6,000 over a period of 2 years and they want you to pay for the handset, I'm sorry, but that is about as greedy as it gets.
&lt;/p&gt;
&lt;p&gt;
In contrast, Telstra in Australia is offering the iPhone for free with a A$100 a month plan on a two-year contract. Which seems a little more reasonable!
&lt;p&gt;
I'm predicting there is now going to be somewhat of a blackmarket of iPhone's as people attempt to import them from elsewhere, jailbroken, to avoid any lame Vodafone plans that literally cost you an arm and leg.
&lt;/p&gt;
&lt;p&gt;
Next time Vodafone, sort your stuff out!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Update:&lt;/strong&gt; Several others share the same thoughts &lt;a href="http://mothership.co.nz/blog/index.php/2008/07/08/iphone-rate-plans/"&gt;here&lt;/a&gt;, &lt;a href="http://blogs.nzherald.co.nz/blog/your-views/2008/7/8/what-do-you-think-vodafones-iphone-pricing-plan/?c_id=1501154"&gt;here&lt;/a&gt; and &lt;a href="http://www.geekzone.co.nz/iphone/5335"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;Unfortunately Stuff.co.nz &lt;a href="http://www.stuff.co.nz/4610626a28.html"&gt;reported it as being in-expensive&lt;/a&gt;. And then updated to say it was expensive - get it right the first time guys!
&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=3xD9XJ"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=3xD9XJ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=mcCDAj"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=mcCDAj" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=OVvinj"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=OVvinj" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=H11Nsj"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=H11Nsj" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Ruby on Rails: From Hackers to the Enterprise</title><link>http://www.d-jones.com/2008/6/27/ruby-on-rails-from-hackers-to-the-enterprise</link><category>Ruby on Rails</category><category>White Papers</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Wed, 09 Jul 2008 22:42:30 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-06-27:52</guid><description>I was there in mid 2004. I was using Ruby on Rails when its version number was a small decimal. It wasn’t my fault, a few years of PHP is enough to make anyone take the plunge. I set aside a couple of weeks until I got confident and in week three I had my first commercial Rails application built and live. Now four years later, I have never looked back.

At the time, the Rails community was nothing more than 100 hackers hanging around online trying to help each other out with a common goal of writing beautiful code for their applications. Now Rails has become somewhat of a hot topic online.  But how did creator David Heinemeier Hansson pull this off? How could one man make such a huge dent in the development of web applications?

At first there was resistance. Rails has always been very firm on how you do things, there is little choice, you do it the Rails way or you’re doing it wrong. And it’s this very controversial approach that has been key to beating the resistance of uptake. It’s amplified the gap. Instead of having a few people who think Rails is alright, you get a mere two types of people, lovers and haters. There is no fence sitting here. These dedicated programmers spoke to their friends and with a strong opinion managed to pull in more Rails recruits.

Then there was denial. Now with a healthy backing of strong opinioned Rails hackers, Rails was starting to show up on respected industry sites like SlashDot in early 2005. The word was starting to spread. Along with outrageous claims like “Rails will make you 10 times as productive”. If anyone told me that, damn straight I’d deny it too.

Then there were copycats. Slowly but surely programmers in other languages started to work out that Rails was exactly what they were looking for. So what did they do? They took the architecture of the Rails framework and wrote it in the language of their choice. CakePHP for PHP cropped up in 2005, then Pylons for Python and even Microsoft is starting to show some similarities with their latest ASP.NET MVC framework. They always have said imitation is the sincerest form of flattery.

Then came the large start-ups. Start-ups took the risk and capitalised on the ability to start from the beginning in Rails. And boy did they ever! Sites like twitter.com, 43things.com and odeo.com were bang on the money. But the enterprise still resisted. No one ever got fired for choosing Microsoft right?

And here comes the enterprise. In 2006 and 2007, Rails got really bagged for not being able to scale. Now sites like twitter.com, which was recorded in 2008 to handle over 3 million twitter messages a day, you can’t doubt that Rails can and does truly scale.

But the hosting environment Rails needed has always been a good excuse not to use Rails. If your web framework doesn’t run on a standard open source enterprise web server like Apache, the enterprise isn’t going to even notice you.

But that issue is now solved too. Recently mod_rails was released, a module that allows you to run Rails properly on Apache, and is what I believe is going to see a frenzy of growth in the uptake of Rails in the enterprise. David HH said himself “This could become very popular, very fast!” and he’s absolutely right.

Rails is now, in 2008, being used by some seriously big names, Amazon.com, The BBC, IBM, Apple Computer, yellowpages.com and NASA to name a few. And it’s grown around the world with Rails development companies setting up shop just about everywhere.

It’s been a long hard push uphill to bring Rails to the enterprise and there is a long way to go yet, but both feet are well in the door.

&amp;lt;script src="http://w.sharethis.com/widget/?tabs=web%2Cpost%2Cemail&amp;amp;charset=utf-8&amp;amp;style=default&amp;amp;publisher=6063ab5f-1944-4013-be77-be03fc4e1eb2&amp;amp;popup=true" type="text/javascript"&gt;&amp;lt;/script&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=FlwkqI"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=FlwkqI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=2YNCdi"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=2YNCdi" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=qkzuWi"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=qkzuWi" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=c1HvBi"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=c1HvBi" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Simulating Different Connection Speeds in OS X</title><link>http://www.d-jones.com/2008/6/16/simulating-different-connection-speeds-in-os-x</link><category>How To's</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Sun, 15 Jun 2008 21:49:14 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-06-16:49</guid><description>&lt;p&gt;
When developing a website or app it's useful to see what things feel like at different speeds.
&lt;/p&gt;
&lt;p&gt;
I just wanted to share the commands I've been using to acheive this. You could use this for limiting your traffic if you're downloading something but don't want to hog your connection if it's shared.
&lt;/p&gt;
&lt;p&gt;
So pop open Terminal.app and try the following:&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Limiting port 80 to dialup speed:&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;
sudo ipfw pipe 1 config bw 7KByte/s;sudo ipfw add 1 pipe 1 src-port 80;echo '\''Limiting port 80 to 7kbps'\'
&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Removing the limit and restoring port 80 back to full speed:&lt;/strong&gt;&lt;br /&gt;
&lt;code&gt;
sudo ipfw delete 1;echo '\''Traffic resuming at full speed!'\'
&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;And of course you can alter the speed and port to whatever you like.
&lt;/p&gt;
&lt;p&gt;
So there you have it, an easy little tip. Comes in handy at times, trust me.
&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=bqkWoI"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=bqkWoI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=X2KX2i"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=X2KX2i" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=RFWGri"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=RFWGri" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=zkCN0i"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=zkCN0i" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>How To Fix Textile Paragraphs in Rails</title><link>http://www.d-jones.com/2008/6/5/fixing-textile-paragraphs-in-rails</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Wed, 04 Jun 2008 19:11:34 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-06-05:48</guid><description>&lt;p&gt;
Rails has a &lt;a href="http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M001054"&gt;built in textilize() method&lt;/a&gt; but it by default treats a new line as a BR tag. Which is really lame and annoying.
&lt;/p&gt;
&lt;p&gt;
The code the Rails textilize() method uses is:&lt;br /&gt;
&lt;code&gt;textilized = RedCloth.new(text, [ :hard_breaks ])&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
What this does is causes some textile text like this
&lt;pre&gt;
h1. Birds

I know all about birds. They have wings.

Birds eat worms.
&lt;/pre&gt;
&lt;p&gt;
into this HTML
&lt;/p&gt;
&lt;p&gt;
&lt;pre&gt;
&lt;h1&gt;Birds&lt;/h1&gt;
&lt;br /&gt;
I know all about birds. They have wings.
&lt;br /&gt;
Birds eat worms.
&lt;/pre&gt;
&lt;p&gt;Not good code at all!&lt;/p&gt;
&lt;h2&gt;The Solution&lt;/h2&gt;
&lt;p&gt;Rails by default isn't behaving how we need it so we have to override the method Rails uses. We do this by creating our own textilize() method in our application helper that doesn't include the &lt;code&gt;[:hard_breaks]&lt;/code&gt; option Rails does.&lt;/p&gt;
&lt;code&gt;&lt;pre&gt;
module ApplicationHelper
  
  def textilize(text) # overriding Rails method to remove hardbreaks
    if text.blank?
     ""
    else
     textilized = RedCloth.new(text).to_html
    end
  end
  
end
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;So there you have it. Call the Textilize method now and you're Textile will be nicely formatted with paragraphs.&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=YYpKII"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=YYpKII" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=S0dpoi"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=S0dpoi" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=ZpMFmi"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=ZpMFmi" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=fb3PHi"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=fb3PHi" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Out with Photoshop and in with Pixelmator</title><link>http://www.d-jones.com/2008/3/25/image-editing-mac-osx-photoshop-pixelmator</link><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Mon, 24 Mar 2008 21:39:17 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2008-03-25:47</guid><description>&lt;p&gt;Abobe Photoshop is the industry standard image editing software, but today I've made the switch to &lt;a href="http://www.pixelmator.com/"&gt;Pixelmator&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;
Photoshop isn't that fast on a Mac nor is it very "Mac-like". And this is where I find Pixelmator really good. It's simple, insanely fast to startup and takes about 2 seconds to learn if you know Photoshop. Everything is pretty much in the same place as Photoshop which I imagine is why &lt;a href="http://www.gimpshop.com/"&gt;Gimpshop&lt;/a&gt; has become so successful. And I really love the black interface they've slapped onto it.&lt;/p&gt;

&lt;p&gt;For US$59 ($NZ78.74) it's a steal in comparison to Photoshop so consider making the switch if you're on a Mac!&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=LcGp2vF"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=LcGp2vF" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=6eG9wZf"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=6eG9wZf" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=2BmlJNf"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=2BmlJNf" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/djones_blog?a=KbMwhLf"&gt;&lt;img src="http://feeds.feedburner.com/~f/djones_blog?i=KbMwhLf" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>How to Fix Validation Alignment Issues in Rails</title><link>http://www.d-jones.com/2007/12/26/how-to-fix-validation-alignment-issues-in-rails</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Tue, 25 Dec 2007 21:02:50 -0600</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-12-26:46</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>Here's a real quick tip which fixes a problem I've come across time and time again.</p>
<p>Consider the form below:</p>

<img src="/assets/2007/normal-form.png" alt="Wine Form" />
<p>Here's a real quick tip which fixes a problem I've come across time and time again.</p>
<p>Consider the form below:</p>

<img src="/assets/2007/normal-form.png" alt="Wine Form" />

<p>Here's a snippet of what the code looks like to create 3 of those fields:</p>
<code><pre>
<div class="field">
	&lt;%= f.label(:vintage) %>
	&lt;%= f.text_field :vintage, :size => 5 %> <small>Optional - e.g. 1990</small>
</div>
<div class="field">
	&lt;%= f.label(:alcohol) %>
	&lt;%= f.text_field :alcohol, :size => 5 %>% <small>e.g. 5.6 or 10.25 </small>
</div>
<div class="field">
	&lt;%= f.label(:residual_sugar) %>
	&lt;%= f.text_field :residual_sugar, :size => 5 %> g/L <small>e.g. 45 </small>
</div>
</pre>
</code>
<p>You can see I've added a few little side notes next to each field using the small tag. The problem with adding a note inline next to a field in Rails is when the form is submitted and the data isn't valid. The form returned looks like this:</p>

<img src="/assets/2007/form-with-errors.png" alt="Form with Errors" />

<p>As you can see, the little notes get pushed over onto the next line. That's because Rails puts a div around the fields that are invalid. These divs are assigned a "fieldWithErrors" class. Now this can be useful for highlighting fields that have errors. For example, I like to highlight the label for the field with an error in red text. So I add this to my CSS:
</p>

<code><pre>
div.fieldWithErrors label {
	color: #933; /* mid to dark red */
}
</pre>
</code>
<p>And that works great, but we still have this problem with the field notes jumping down. The reason for that is because the element Rails uses to put around the invalid field is a div and by default a div is displayed as a block element. We can fix this problem by forcing the browser to render it as an inline element by using the following CSS:</p>
<code><pre>
div.fieldWithErrors {
	display: inline;
}
</pre>
</code>
<p>Now it looks like this:</p>
<img src="/assets/2007/form-with-errors-fixed.png" alt="Form with Errors - Fixed" />

<p>So there you have it. A simple little tip some of you out there might find useful.</p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=hLyMvhC"><img src="http://feeds.feedburner.com/~f/djones_blog?i=hLyMvhC" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=05alT8c"><img src="http://feeds.feedburner.com/~f/djones_blog?i=05alT8c" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=FbFESxc"><img src="http://feeds.feedburner.com/~f/djones_blog?i=FbFESxc" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=mTyTt0c"><img src="http://feeds.feedburner.com/~f/djones_blog?i=mTyTt0c" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;Here's a real quick tip which fixes a problem I've come across time and time again.&lt;/p&gt;
&lt;p&gt;Consider the form below:&lt;/p&gt;

&lt;img src="/assets/2007/normal-form.png" alt="Wine Form" /&gt;</description></item><item><title>How to add Cropping Support to Acts_As_Attachment</title><link>http://www.d-jones.com/2007/10/11/cropping-support-for-acts_as_attachment</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Thu, 11 Oct 2007 18:17:11 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-10-11:42</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>
<a href="http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment">Acts_as_attachment</a> really kicks arse when it comes to handling files and images in your Rails application but one thing the <a href="http://www.kanthak.net/opensource/file_column/">file_column plugin</a> has over acts_as_attachment is cropping support. Time and time again <a href="http://www.resolvedigital.com">at work</a> we have a space in the design for an image which has to be a certain size. By that I mean it must have a set width and height. But the client needs to be able to put any image they want into that space. But what if they upload a bigger image? Or, what if it's different aspect ratio?
</p>


<p>
<a href="http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment">Acts_as_attachment</a> really kicks arse when it comes to handling files and images in your Rails application but one thing the <a href="http://www.kanthak.net/opensource/file_column/">file_column plugin</a> has over acts_as_attachment is cropping support. Time and time again <a href="http://www.resolvedigital.com">at work</a> we have a space in the design for an image which has to be a certain size. By that I mean it must have a set width and height. But the client needs to be able to put any image they want into that space. But what if they upload a bigger image? Or, what if it's different aspect ratio?
</p>
<h2>Example</h2>
<p>Imagine you've got a client that trains dogs. They're revising their home page and the designer has come up with a design that has space for 3 images that are exactly the same size. The designer thinks this looks great, but now you're stuck with the problem of how can you let the client upload any image of any size or aspect ratio and have them perfectly fit into those 3 boxes.</p>
<img src="/assets/2007/10/11/step1.jpg" alt="Step one" />
<p>
Acts_as_attachment allows you to resize images which is useful when you can have a fixed width or height, but the other is variable. But in this case the designer wants 3 images which are all the same size, both in height and width. This is what would happen if we used acts_as_attachment to resize the images using a fixed width, but variable height.
</p>
<img src="/assets/2007/10/11/step2.jpg" alt="Step two: Resizing only" />

<p>Out of the box, this is actually your best option. But I've taken acts_as_attachment one step further and added cropping support. This will allow us to resize, then crop the image so that it's scaled down, and then the left over bits are cropped off so that we can fit any image in these 3 boxes of fixed height and width. This is the results of using resizing and cropping:</p>
<img src="/assets/2007/10/11/step3.jpg" alt="Step Three: Resizing and Cropping" />
<p>Now the client can be confident they can upload any image they like and it's going to look nice on the site.</p>
<h2>Patching Acts_as_Attachment to Support Cropping</h2>
<p>
Once you've installed the acts_as_attachment plugin, find the <code>thumbnail_for_image</code> method which is in /vendor/plugins/acts_as_attachment/lib/technoweenie/acts_as_attachment.rb
</p>
<p>
For me the <code>thumbnail_for_image</code> method begins on line 242. This might be different for you. The method should look like this:
<code><pre>
def thumbnail_for_image(img, size)
  size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
  if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
    size = [size, size] if size.is_a?(Fixnum)
    img.thumbnail(size.first, size[1])
  else
    img.change_geometry(size.to_s) { |cols, rows, image| image.resize(cols, rows) }
  end
end
</pre></code>
To add cropping support, change it to this:
<code><pre>
def thumbnail_for_image(img, size)
  size = size.first if size.is_a?(Array) && size.length == 1 && !size.first.is_a?(Fixnum)
  if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
    size = [size, size] if size.is_a?(Fixnum)
    img.thumbnail(size.first, size[1])
  elsif size.is_a?(String) && size =~ /^c.*$/ # Patch to enable cropping
    dimensions = size[1..size.size].split("x")
    img.crop_resized!(dimensions[0].to_i, dimensions[1].to_i)
  else
    img.change_geometry(size.to_s) { |cols, rows, image| image.resize(cols, rows) }
  end
end
</pre></code>
<p>Save and restart your web app and you should be up and running with cropping support!
<h2>How to Indicate you Want Cropping</h2>
<p>
In your model all you need to do is put a "c" infront of the dimensions on the thumbnail you want to resize and crop. The "c" indicates to acts_as_attachment that cropping should occur.
<code><pre>
acts_as_attachment :storage => :file_system,
                   :file_system_path => 'public/system', # Using Capistrano conventions
                   :max_size => 4.megabytes,
                   :content_type => :image, # only allow png, gif and jpg
                   :resize_to => "1000x1000",
                   :thumbnails => {:home => "c100x80",
                                            :something_else => "500>"}
</pre></code>
For the example above you might make a new thumbnail called "home". We've put a c infront of it to make sure the cropping occurs. The result should be an image fixed at 100x80 regardless of what size or aspect ratio the client uploads.
</p>
<h2>Extending this Idea Further</h2>
<p>If you take a look at the modifcations to acts_as_attachment to support cropping, you could easily modify it to support anything you like. Perhaps on a certain thumbnail you want a drop shadow to appear. You could make acts_as_attachment recognise "s" (for 'shadow') infront of the deminsions.</p>
<p>If you do anything cool like that please comment below and let us know!</p>

<p><small>Images used in example taken from <a href="http://www.dogbitelaw.com/graphics/dogs-running.jpg">here</a>, <a href="http://web.media.mit.edu/~nicholas/dog-1.JPG">here</a> and <a href="http://dogtownsend.com/images/dog28.jpg">here</a>.</small></p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=lXxW1teH"><img src="http://feeds.feedburner.com/~f/djones_blog?i=lXxW1teH" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=XnONTcVo"><img src="http://feeds.feedburner.com/~f/djones_blog?i=XnONTcVo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=JPd4PkTQ"><img src="http://feeds.feedburner.com/~f/djones_blog?i=JPd4PkTQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=CePr5kII"><img src="http://feeds.feedburner.com/~f/djones_blog?i=CePr5kII" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;
&lt;a href="http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment"&gt;Acts_as_attachment&lt;/a&gt; really kicks arse when it comes to handling files and images in your Rails application but one thing the &lt;a href="http://www.kanthak.net/opensource/file_column/"&gt;file_column plugin&lt;/a&gt; has over acts_as_attachment is cropping support. Time and time again &lt;a href="http://www.resolvedigital.com"&gt;at work&lt;/a&gt; we have a space in the design for an image which has to be a certain size. By that I mean it must have a set width and height. But the client needs to be able to put any image they want into that space. But what if they upload a bigger image? Or, what if it's different aspect ratio?
&lt;/p&gt;</description></item><item><title>How to Test Change with assert_difference() in Rails</title><link>http://www.d-jones.com/2007/8/28/test-change-assert_difference-method-rails</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Tue, 28 Aug 2007 17:10:26 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-08-28:37</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>
The Rails core team have really been kicking out some cool stuff recently. One addition I've been taking full advantage of is the <code>assert_differnce()</code> method (<a href="http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/test/difference.rb?rev=6647">changeset here</a>). This method is only available to those of you who are using Edge Rails.
</p>
<p>
If you need to test something that changes, then <code>assert_differnce()</code> is perfect. Below is a typical example of something changing. We have a user class and we want to test the destroy method to make sure the user really does get destroyed.
</p>
<p>
The Rails core team have really been kicking out some cool stuff recently. One addition I've been taking full advantage of is the <code>assert_differnce()</code> method (<a href="http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/test/difference.rb?rev=6647">changeset here</a>). This method is only available to those of you who are using Edge Rails.
</p>
<p>
If you need to test something that changes, then <code>assert_differnce()</code> is perfect. Below is a typical example of something changing. We have a user class and we want to test the destroy method to make sure the user really does get destroyed.
</p>
<p>
Let's take a step back for a moment. What changes when this user is deleted? User.count does, because there is now one less user to count. So we need to ensure that there is a difference in the count of users after deleting a user.
</p>
<h2>Before</h2>
<pre><code>
class UserTest &lt; Test::Unit::TestCase

  fixtures :users

  def test_should_delete_first_user
    # Record current user count
    old_count = User.count  

    # Delete the first user we find
    User.find(:first).destroy

    # Make sure the count is now 1 less than it was before
    assert_equal old_count -1, User.count  
  end

end
</code></pre>
<h2>After (using assert_difference)</h2>
<pre><code>
class UserTest &lt; Test::Unit::TestCase

  fixtures :users

  def test_should_delete_first_user
    assert_difference('User.count', -1) do
      User.find(:first).destroy
    end
  end

end
</code></pre>
<p>Ah yes, much nicer.</p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=sUSV9Szs"><img src="http://feeds.feedburner.com/~f/djones_blog?i=sUSV9Szs" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=3laMMFpF"><img src="http://feeds.feedburner.com/~f/djones_blog?i=3laMMFpF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=yCK9UJGm"><img src="http://feeds.feedburner.com/~f/djones_blog?i=yCK9UJGm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=hMsctNMI"><img src="http://feeds.feedburner.com/~f/djones_blog?i=hMsctNMI" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;
The Rails core team have really been kicking out some cool stuff recently. One addition I've been taking full advantage of is the &lt;code&gt;assert_differnce()&lt;/code&gt; method (&lt;a href="http://dev.rubyonrails.org/browser/trunk/activesupport/lib/active_support/core_ext/test/difference.rb?rev=6647"&gt;changeset here&lt;/a&gt;). This method is only available to those of you who are using Edge Rails.
&lt;/p&gt;
&lt;p&gt;
If you need to test something that changes, then &lt;code&gt;assert_differnce()&lt;/code&gt; is perfect. Below is a typical example of something changing. We have a user class and we want to test the destroy method to make sure the user really does get destroyed.
&lt;/p&gt;</description></item><item><title>6 Style Guidelines for CSS</title><link>http://www.d-jones.com/2007/7/16/style-guidelines-for-css</link><category>How To's</category><category>White Papers</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Tue, 17 Jul 2007 01:23:45 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-07-16:36</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>It's important to keep a consistant style when writing CSS. When you have a team of developers you might want to consider writing a guideline that everyone follows and agrees to.</p>

<p>Here are some guidelines I follow...</p>
<p>It's important to keep a consistant style when writing CSS. When you have a team of developers you might want to consider writing a guideline that everyone follows.</p>

<p>Here are some guidelines I follow...</p>

<ol>
<li>Always combine statements that can be combined. One line is shorter and sweeter. It groups all statements of the same type together which is useful and easier to access. For example:
<code>
<pre>
/* Better */
background: url(background.png) #00FF00 no-repeat;

/* Bad */
background-image: url(background.png);
background-color: #00FF00;
background-repeat: no-repeat;
</pre>
</code>
</li>
<li>
	Always use words for colours where possible. If you're dealing with a basic developer they're far more likely to recognise the word of the colour than the hex value. 
<code>
<pre>
/* Better */
color: white;

/* Bad */
color: #FFFFFF;
</pre>
</code>
</li>
<li>
Shorten hex colours where possible. Short and sweet.
<code>
<pre>
/* Better */
color: #F0F;

/* Bad */
color: #FF00FF;
</pre>
</code>
</li>
<li>
Hex values are easier to spot and read when in capitals.
<code>
<pre>
/* Better */
color: #F0F;

/* Bad */
color: #f0f;
</pre>
</code>
</li>

<li>
All hacks should be linked to documentation in a comment. Hacks can be pretty confusing looking to many CSS developers, so why not do them a favour and link them to some relevant documentation so they can go read up about it!
<code>
<pre>
/* Clearfix hack, see http://www.positioniseverything.net/easyclearing.html */
.clearfix:after {
    content: "."; 
    display: block; 
    height: 0; 
    clear: both; 
    visibility: hidden;
}
/* ... snip ... */
</pre>
</code>
</li>
<li>
Be careful not to duplicate CSS or forget to remove redudant CSS. We've all done this, written some CSS and then removed the HTML it was styling but never removed the CSS. <a href="http://code.google.com/p/css-redundancy-checker/">CSS redundancy checker</a> to the rescue! This Ruby script will run through your CSS and find and remove redundant CSS for you.
</li>
</ol>
<p>These are just 6 guidlines I follow. <strong>Comment if you have one of your own to add...</strong></p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=RpoI6GUY"><img src="http://feeds.feedburner.com/~f/djones_blog?i=RpoI6GUY" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=iA38nnnX"><img src="http://feeds.feedburner.com/~f/djones_blog?i=iA38nnnX" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=Ra0q0Ac6"><img src="http://feeds.feedburner.com/~f/djones_blog?i=Ra0q0Ac6" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=0tBmHPim"><img src="http://feeds.feedburner.com/~f/djones_blog?i=0tBmHPim" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;It's important to keep a consistant style when writing CSS. When you have a team of developers you might want to consider writing a guideline that everyone follows and agrees to.&lt;/p&gt;

&lt;p&gt;Here are some guidelines I follow...&lt;/p&gt;</description></item><item><title>How to Reduce the Size of your PNGs with CrushPNG</title><link>http://www.d-jones.com/2007/6/11/reduce-photoshop-png-image-size-with-crushpng</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Sun, 08 Jul 2007 16:25:11 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-06-11:23</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>According to <a href="http://www.libpng.org/pub/png/pngapbr.html">Roelofs</a>, it's a popular misconception that few browsers support PNG. In fact, Microsoft Internet Explorer, Netscape Communicator, and Opera have supported it since 1997.</p>

<p>Roelofs is right, however, full alpha transparency support didn't exist in Internet Explorer until version 7. With this new support for transparency, the advantages of using PNG only become more and more obvious.</p>

<p>However, the plot thickens when you save a PNG file from Adobe Photoshop. Photoshop does a poor job of compressing PNG images properly.</p>

<p><a href="http://pmt.sourceforge.net/pngcrush/">CrushPNG</a> to the rescue! CrushPNG is a lossless PNG optimiser that will reduce the size of your PNG images in a flash.</p>

<p>To install with Ports simple run:</p>
<pre><code>
sudo port install crushpng
</code></pre>
<p>Otherwise, download it from <a href="http://sourceforge.net/project/showfiles.php?group_id=1689">here</a>.</p>
<p>According to <a href="http://www.libpng.org/pub/png/pngapbr.html">Roelofs</a>, it's a popular misconception that few browsers support PNG. In fact, Microsoft Internet Explorer, Netscape Communicator, and Opera have supported it since 1997.</p>

<p>Roelofs is right, however, full alpha transparency support didn't exist in Internet Explorer until version 7. With this new support for transparency, the advantages of using PNG only become more and more obvious.</p>

<p>However, the plot thickens when you save a PNG file from Adobe Photoshop. Photoshop does a poor job of compressing PNG images properly.</p>

<p><a href="http://pmt.sourceforge.net/pngcrush/">CrushPNG</a> to the rescue! CrushPNG is a lossless PNG optimiser that will reduce the size of your PNG images in a flash.</p>

<p>First you will need to install CrushPNG with Ports. Simply run:</p>
<pre><code>
sudo port install crushpng
</code></pre>
<p>Otherwise, download it from <a href="http://sourceforge.net/project/showfiles.php?group_id=1689">here</a>.</p>
<p>
Here is the basic syntax to optimise a PNG image:
</p>
<pre>
<code>
crushpng before.png after.png
</code>
</pre>
<p>If you're like me, you'll have an images directory for your website. So typically I would want to make sure all my PNG images are optimised. You could manually optimise each file but that could be a little tedious and time consuming. So I've written up a command that will recursively go through your files looking for PNG images, optimise them and then finally save them.
</p>
<p>The command looks like this:
</p>
<pre><code>
find . -name "*.png" -exec pngcrush -brute -force -q {} temp.png \;  -exec rm {} \;  -exec mv temp.png {} \; -print
</code></pre>
<p>This is quite a long command and I'm hoping you're not crazy enough to remember that. So we can set it as an alias instead. Do the following to setup this command as an alias:
</p>
<pre><code>
cd ~
mate .profile # I use TextMate, you could use nano .profile here if you wanted to
</code></pre>
<p>
Now add this line into your .profile file and save it.
</p>
<pre><code>
alias crushpngs="find . -name \"*.png\" -exec pngcrush -brute -force -q {} temp.png \;  -exec rm {} \;  -exec mv temp.png {} \; -print"
</code></pre>
<p>Reopen terminal and now you can just use the "crushpngs" command anywhere you like. The particular use I have for this is in my latest project <a href="http://www.myletterbox.co.nz">MyLetterBox</a>. Here is an example of the command running on a <a href="http://www.rubyonrails.org/">Ruby on Rails application</a>:</p>
<code><pre>
~/Code/MyLetterBox/trunk/public/images$ crushpngs
./application/bottom-gradient.png
./application/myletterbox-logo.png
./application/top-gradient.png
./buttons/notify-me.png
~/Code/MyLetterBox/trunk/public/images$ 
</pre>
</code>
<p>At some point soon I will write up an article on how to add this to your <a href="http://www.capify.org/">Capistrano</a> deploy.rb file. That way you can just deploy your application and it will automatically optimise all your PNG images for you.
</p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=vVhyJz3o"><img src="http://feeds.feedburner.com/~f/djones_blog?i=vVhyJz3o" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=3uR2L04O"><img src="http://feeds.feedburner.com/~f/djones_blog?i=3uR2L04O" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=C4ntXe3m"><img src="http://feeds.feedburner.com/~f/djones_blog?i=C4ntXe3m" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=F6ExZfzn"><img src="http://feeds.feedburner.com/~f/djones_blog?i=F6ExZfzn" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;According to &lt;a href="http://www.libpng.org/pub/png/pngapbr.html"&gt;Roelofs&lt;/a&gt;, it's a popular misconception that few browsers support PNG. In fact, Microsoft Internet Explorer, Netscape Communicator, and Opera have supported it since 1997.&lt;/p&gt;

&lt;p&gt;Roelofs is right, however, full alpha transparency support didn't exist in Internet Explorer until version 7. With this new support for transparency, the advantages of using PNG only become more and more obvious.&lt;/p&gt;

&lt;p&gt;However, the plot thickens when you save a PNG file from Adobe Photoshop. Photoshop does a poor job of compressing PNG images properly.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://pmt.sourceforge.net/pngcrush/"&gt;CrushPNG&lt;/a&gt; to the rescue! CrushPNG is a lossless PNG optimiser that will reduce the size of your PNG images in a flash.&lt;/p&gt;

&lt;p&gt;To install with Ports simple run:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
sudo port install crushpng
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Otherwise, download it from &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=1689"&gt;here&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>How to Export All Your Products From Shopify in XML</title><link>http://www.d-jones.com/2007/5/7/how-to-export-all-your-products-from-shopify-in-xml</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Sun, 06 May 2007 21:55:01 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-05-07:20</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>
As part of some on the side work I'm doing for <a href="http://hanafins.co.nz/">Hanafins</a>, I needed to syncronise products added in <a href="http://shopify.com/">Shopify</a> with <a href="http://www.ferrit.co.nz/">Telecom's Ferrit ecommerce system</a>. To do this, you need to be able to export all the products out of Shopify. This isn't easy as the Shopify API isn't ready yet.</p>
<p>
In the meantime, use the script below to emulate a browser logging in and request the products.xml file.
</p>
<p>
As part of some on the side work I'm doing for <a href="http://hanafins.co.nz/">Hanafins</a>, I needed to syncronise products added in <a href="http://shopify.com/">Shopify</a> with <a href="http://www.ferrit.co.nz/">Telecom's Ferrit ecommerce system</a>. To do this, you need to be able to export all the products out of Shopify. This isn't easy as the Shopify API isn't ready yet.</p>
<p>
In the meantime, use the script below to emulate a browser logging in and request the products.xml file.
</p>
<h2>The Code</h2>
<p>
Firstly you'll want to install the 'mechanize' gem.
</p>
<pre><code>
sudo gem install mechanize --include-dependencies
</code></pre>
<p>
Is this example we're using a Shopify model and a download_xml method.
</p>
<pre><code>
require 'mechanize' # Required to login and download the products feed
  
# This model handles the downloading of the Shopify XML feed
class Shopify &lt; ActiveRecord::Base

  URL = "http://yourstore.myshopify.com"
  LOGIN = "you@youremail.com"
  PASSWORD = "yourpassword"

  # Download the XML feed from Shopify
  def download_xml
    # Request the login page
    agent = WWW::Mechanize.new
    page = agent.get("#{URL}/admin/auth/login")

    # Input the login creditionals into the form
    form = page.forms.first
    form.login = LOGIN
    form.password = PASSWORD
    page = agent.submit(form, form.buttons.first)
    
    # Request all the products in the store. Stops at 10,000 products.
    page = agent.get("#{URL}/admin/products.xml?limit=10000")
    page.body
  end

end
</code></pre>
<p>
And that's it! So now in your controller you could go:
</p>
<pre><code>
  products_xml = Shopify.new.download_xml
  render :text => products_xml
</code></pre>
<p>
And you would get all the products outputted in XML from your Shopify store.</p>
<h2>Related Documentation</h2>
<p><a href="http://mechanize.rubyforge.org/mechanize/">Mechanize RDoc's</a></p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=5o35GKxt"><img src="http://feeds.feedburner.com/~f/djones_blog?i=5o35GKxt" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=nnufvrH3"><img src="http://feeds.feedburner.com/~f/djones_blog?i=nnufvrH3" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=W38h5hmC"><img src="http://feeds.feedburner.com/~f/djones_blog?i=W38h5hmC" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=rEflVb4P"><img src="http://feeds.feedburner.com/~f/djones_blog?i=rEflVb4P" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;
As part of some on the side work I'm doing for &lt;a href="http://hanafins.co.nz/"&gt;Hanafins&lt;/a&gt;, I needed to syncronise products added in &lt;a href="http://shopify.com/"&gt;Shopify&lt;/a&gt; with &lt;a href="http://www.ferrit.co.nz/"&gt;Telecom's Ferrit ecommerce system&lt;/a&gt;. To do this, you need to be able to export all the products out of Shopify. This isn't easy as the Shopify API isn't ready yet.&lt;/p&gt;
&lt;p&gt;
In the meantime, use the script below to emulate a browser logging in and request the products.xml file.
&lt;/p&gt;</description></item><item><title>How to use RSS to Keep an Eye on your Clients</title><link>http://www.d-jones.com/2007/4/5/how-to-use-rss</link><category>How To's</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Wed, 04 Apr 2007 23:21:09 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-04-05:18</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>
Sometimes when I have completed a website for a client, I wonder if they are really using it correctly. With some clients, you can build them the coolest backend but they don't use it to its fullest extent. It's not that they are stupid, but perhaps something was overlooked which is making it difficult for the client.
</p>
<p>
If you give a client the tools to update a website themselves you'd like to hope they will actually take advantage of your hard work.
</p>
<p>
This is where I have found <acronym title="Really Simple Syndication">RSS</acronym> handy in my latest project.
</p>
<p>
Sometimes when I have completed a website for a client, I wonder if they are really using it correctly. With some clients, you can build them the coolest backend but they don't use it to its fullest extent. It's not that they are stupid, but perhaps something was overlooked which is making it difficult for the client.
</p>
<p>
If you give a client the tools to update a website themselves you'd like to hope they will actually take advantage of your hard work.
</p>
<p>
This is where I have found <acronym title="Really Simple Syndication">RSS</acronym> handy in my latest project.
</p>
<h2>Use RSS to Spy on your Clients</h2>
<p>
Okay, so it's not really spying... but the client I was dealing with is very new to computers. I had to make it as simple as possible for her use. I also wanted to make sure she was able to use it.
</p>
<p>
When I built the backend, I always had to keep in mind the ability of the client. But once you show the client your beautiful polished work, you can never really be sure what problems they will have when you're not around.
</p>
<p>
By placing <acronym title="Really Simple Syndication">RSS</acronym> feeds around the site I was able to track when the client was updating the website as they did it. I could check right away if they had made any mistakes.
</p>
<h2>Correcting Mistakes Early &amp; Quickly Makes Happier Clients</h2>
<p>
I was able to ring my client up, correct a few things and educate the client from what I could see they needed improving on.
</p>
<p>Because of <acronym title="Really Simple Syndication">RSS</acronym> I knew right away she was updating the website so when I called her of course, she was right in front of the computer with the backend open ready to hear what I had to say.
</p>
<p>
That day I had also been making alterations to the code which caused a problem. It was only until the site was altered by the client that this problem occurred. Because I could check the site as she was updating it, I found the problem as soon as she made the changes and fixed it promptly before anyone could see.
</p>
<h2>A website project is an ongoing thing</h2>
<p>
Most website projects I've been involved in have been an on-going pieces of work. You can never say a website is "complete" and never touch it again. You have to update and maintain it and <acronym title="Really Simple Syndication">RSS</acronym> is a great way to keep up to date with how the client is going.
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=vKGpV6fH"><img src="http://feeds.feedburner.com/~f/djones_blog?i=vKGpV6fH" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=NS4foVkD"><img src="http://feeds.feedburner.com/~f/djones_blog?i=NS4foVkD" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=IPOF4C7l"><img src="http://feeds.feedburner.com/~f/djones_blog?i=IPOF4C7l" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=2RtkfAQT"><img src="http://feeds.feedburner.com/~f/djones_blog?i=2RtkfAQT" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;
Sometimes when I have completed a website for a client, I wonder if they are really using it correctly. With some clients, you can build them the coolest backend but they don't use it to its fullest extent. It's not that they are stupid, but perhaps something was overlooked which is making it difficult for the client.
&lt;/p&gt;
&lt;p&gt;
If you give a client the tools to update a website themselves you'd like to hope they will actually take advantage of your hard work.
&lt;/p&gt;
&lt;p&gt;
This is where I have found &lt;acronym title="Really Simple Syndication"&gt;RSS&lt;/acronym&gt; handy in my latest project.
&lt;/p&gt;</description></item><item><title>Google Sitemaps in Ruby on Rails</title><link>http://www.d-jones.com/2007/4/5/google-sitemaps-in-ruby-on-rails</link><category>How To's</category><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Wed, 04 Apr 2007 23:13:48 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-04-05:17</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>From Google's website</p>
<blockquote>
	"If your site has dynamic content or pages that aren't easily discovered by following links, you can use a Sitemap file to provide information about the pages on your site. This helps the spiders know what URLs are available on your site and about how often they change."
</blockquote>
<p>
	I thought it would be a good thing to have Google Sitemaps integrated into some of my Ruby on Rails projects. Because Ruby on Rails has excellent XML support, I went ahead and implemented Google Sitemaps into one of my latest projects.
</p>
<p>From Google's website</p>
<blockquote>
	"If your site has dynamic content or pages that aren't easily discovered by following links, you can use a Sitemap file to provide information about the pages on your site. This helps the spiders know what URLs are available on your site and about how often they change."
</blockquote>
<p>
	I thought it would be a good thing to have Google Sitemaps integrated into some of my Ruby on Rails projects. Because Ruby on Rails has excellent XML support, I went ahead and implemented Google Sitemaps into one of my latest projects.
</p>
<h2>The Controller</h2>
<p>
	Nearly every site I've made so far in Rails has a page controller. So in this example I will use a page controller with a sitemap method inside it.
</p>
<pre>
	<code>
class PageController &lt; ApplicationController

  def sitemap
    @pages = Page.find(:all)
    render_without_layout
  end

end
	</code>
</pre>
<p>
	As you can see in my example controller, the Rails application has a page model. You can replace this with as many models as you wish. For example, if you also had news on your application, you might want to add <em>@news= News.find(:all)</em> to the controller and change the view as required.
</p>
<h2>The View (sitemap.rxml)</h2>
<pre>
	<code>
xml.instruct!
xml.urlset(:xmlns=>'http://www.google.com/schemas/sitemap/0.84') {
  for page in @pages
    xml.url {
      xml.loc(url_for :controller=>'page',
                      :action => 'show',
                      :id => page.id,
                      :trailing_slash => true,
                      :only_path => false)
      xml.lastmod(page.updated_on.strftime('%Y-%m-%d'))
    }
  end
}
	</code>
</pre>
<p>
	The RXML is extremely straight-foward as you can see.
</p>
<p>
	With the above setup the output looks like this...
</p>
<pre>
	<code>
&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
  &lt;url>
    &lt;loc>http://localhost:3000/browse/welcome/&lt;/loc>
    &lt;lastmod>2005-08-23&lt;/lastmod>
  &lt;/url>
  &lt;url>
    &lt;loc>http://localhost:3000/browse/contact/&lt;/loc>

    &lt;lastmod>2005-08-23&lt;/lastmod>
  &lt;/url>
  &lt;url>
    &lt;loc>http://localhost:3000/browse/links/&lt;/loc>
    &lt;lastmod>2005-08-23&lt;/lastmod>
  &lt;/url>
  &lt;url>

    &lt;loc>http://localhost:3000/browse/about/&lt;/loc>
    &lt;lastmod>2005-08-23&lt;/lastmod>
  &lt;/url>
&lt;/urlset>
	</code>
</pre>
<h2>Setting up the Route</h2>
<p>
	Google "strongly recommends" that you place the sitemap in the root directory. Eg: <em>http://www.example.com/sitemap.xml</em>
</p>
<p>
	To do this we need to setup a route. Open up <em>config/routes.rb</em> and add...
</p>
<pre>
	<code>
map.connect 'sitemap.xml', :controller => 'page', :action => 'sitemap' 
	</code>
</pre>
<p>
...near the top of the file. Now when we request <em>http://localhost:3000/sitemap.xml</em> the sitemap will appear.
</p>
<h2>Submit your Sitemap to Google</h2>
<p>
	Now you have setup the sitemap you will need to <a href="https://www.google.com/webmasters/sitemaps/docs/en/submit.html">submit it to Google</a>.
</p>
<h2>Update</h2>
<p>
	<a href="http://bdash.net.nz">Mark</a> extends this example by <a href="http://bdash.net.nz/blog/2005/08/25/google-sitemaps-in-rails/">implementing automatic submissions</a> to Google when your sitemap changes.
</p>
<h2>More Information</h2>
<p>
	For more information about Google's Sitemaps take a look at the BETA website:<br>
	<a href="http://www.google.com/webmasters/sitemaps/docs/en/overview.html">http://www.google.com/webmasters/sitemaps/docs/en/overview.html</a>
</p>
<p>
	For information about Rails and XML have a look at:<br>
	<a href="http://api.rubyonrails.com/classes/Builder/XmlMarkup.html">http://api.rubyonrails.com/classes/Builder/XmlMarkup.html</a>
</p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=SB7XEq32"><img src="http://feeds.feedburner.com/~f/djones_blog?i=SB7XEq32" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=bjI6RN1Q"><img src="http://feeds.feedburner.com/~f/djones_blog?i=bjI6RN1Q" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=S7faNDuN"><img src="http://feeds.feedburner.com/~f/djones_blog?i=S7faNDuN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=OCXFLo3S"><img src="http://feeds.feedburner.com/~f/djones_blog?i=OCXFLo3S" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;From Google's website&lt;/p&gt;
&lt;blockquote&gt;
	"If your site has dynamic content or pages that aren't easily discovered by following links, you can use a Sitemap file to provide information about the pages on your site. This helps the spiders know what URLs are available on your site and about how often they change."
&lt;/blockquote&gt;
&lt;p&gt;
	I thought it would be a good thing to have Google Sitemaps integrated into some of my Ruby on Rails projects. Because Ruby on Rails has excellent XML support, I went ahead and implemented Google Sitemaps into one of my latest projects.
&lt;/p&gt;</description></item><item><title>How Would a Business use Blogging as a Customer Relationship Management Tool?</title><link>http://www.d-jones.com/2007/3/27/business-blogging-customer-relationship-management-tool</link><category>White Papers</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Mon, 26 Mar 2007 23:28:17 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-03-27:5</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>
Have you ever wanted to start a blog for your business? If you have, this is a must read before looking any further. This white paper which I wrote as part of my degree, will fully educate you on how you can gain more business from creating the right type of blog for your business.
</p>
<h2>Introduction</h2>
<p>
	To find out how blogging (short for web-logging) can be used as a method of <acronym title="Customer Relationship Management">CRM</acronym> (Customer Relationship Management) we first need to define the two keywords.
</p>
<p>
	Blogging:
</p>
<blockquote>
	"A blog is a user-generated website where entries are made in journal style and displayed in a reverse chronological order." - <a href="http://en.wikipedia.org/wiki/Blogging">Wikipedia (2007)</a>
</blockquote>
<p>
	<acronym title="Customer Relationship Management">CRM</acronym>:
</p>
<blockquote>
	"Acronym for customer relationship management. <acronym title="Customer Relationship Management">CRM</acronym> entails all aspects of interaction a company has with its customer, whether it be sales or service related. <acronym title="Customer Relationship Management">CRM</acronym> an information industry term for methodologies, software, and usually Internet capabilities that help an enterprise manage customer relationships in an organised way."  Creotec (2005)
</blockquote>
<p>
As the definition suggests, blogging is a series of web-based publications and the definition for <acronym title="Customer Relationship Management">CRM</acronym> mentions "<acronym title="Customer Relationship Management">CRM</acronym> entails all aspects of interaction a company has with its customer”. We can see there is a clear overlap here which makes me ask one further question:
</p>
<blockquote>
	How would a business use blogging as a customer relationship management tool?
</blockquote>
<p>
	How and where do they overlap? In what way can regular online posts form and be some sort of interaction between the customer and a company. This question I endeavour to answer in my findings and summarise in my conclusion.
</p>




<h2>Findings</h2>
<h3>Are Blogs Useful?</h3>
<p>
	I found out that yes they certainly are. Like most things on the Internet, there’s great information but there is also worthless information; Weblogs follow this trend.
</p> 
<blockquote>
	"You care about blogs if your organization wants to develop real relationships with customers and wants to do so better than its competitors.<br />
	Blogs aren’t just a media or PR tool. Business blogs are being used by a variety of industries and companies to circumvent the media and the competition to connect directly with customers." - F. Christopher (2005)
</blockquote>
<p>
It’s made clear that blogs can not only make a connection with your customers but actually help you do better than you competition. They’re a very cheap, simple and fast way to give your customers updates on just about anything. They can also create communities and allow value feedback to occur. This feedback is free too because anyone can post an opinion on a blog (in most cases). It is now becoming clear that blogs are useful for these reasons.
</p>

<h3>Types of Blogs</h3>
<p>
	According to F. Christopher (2005) there are six types of business blogs which you can categorise nearly any blog under. When I say business blog, I mean a blog that is related to a company or is the company itself; a blog that has some sort of commercial nature.  These types of blogs directly relate to the question this report attempts to answer:
</p>
<blockquote>
	How Would a Business use Blogging as a Customer Relationship Management Tool?
</blockquote>
<p>
	A business could use any of the following types of blogs as a <acronym title="Customer Relationship Management">CRM</acronym> tool:
</p>
<ul>
	<li>The Tour Guide</li>
	<li>The Recommender</li>
	<li>The Maven</li>
	<li>The Customer Advocate</li>
	<li>The Do-er</li>
	<li>The <acronym title="Chief Executive Officer">CEO</acronym> Blog</li>
</ul>








<h3>The Tour Guide</h3>
<p>
	As the name suggests, this type of blog gives you a guided tour of a company. It gives you a behind the scenes look at what’s going on in the company and perhaps who is behind it all.
</p>
<p>
	From a business perspective this is useful to draw customers in and create good customer relationships because a customer might be very impressed with some of the things they see happening inside the company. They may also feel special being able to see behind the scenes. It makes the customer feel more confident as nothing is being hidden from them.
</p>
<h3>The Recommender</h3>
<p>
	This sort of blog is an intermediary for a customer trying to find information about something. The blog must maintain and build up a reputation for having good recommendations to survive.
</p>
<p>
	This sort of blog is quite different from the others and is also more difficult to create good customer relationships from it. One example could Apple’s iPod. There’re lots of third party products which complement iPods. If Apple created a blog which recommended these third party products to the customers, the customer might become happier with the iPod itself because one of the third party products was something the customer was looking for but Apple didn’t offer it. Just by letting a customer know about another product, indirectly they have become more satisfied with your product as a result of that.
</p>
<h3>The Maven</h3>
<p>
	“The Maven” type of business blog contains posts from experts in a company. Rather than being orientated around the company it’s more about the experts and what they have to say. The blog normally covers a very broad topic rather than something very specific and narrow focused.
</p>
<p>
	Even though the readers of the blog are after expert advice from the writer, it gives the company an appearance of expertise. The user might say to themselves "this expert works for this company, so this company must be really good". If the users can see this expertise, the company might get customers which choose that company over their competition as a result of this.
</p>
<h3>The Customer Advocate</h3>
<p>
	This type of blog is one of the most effective in business. The Customer Advocate blog directly engages with the customer. It allows the customer to write feedback and ask or even answer others questions.
</p>
<p>
	This blog allows a high level of communication which can often be of great help to the company and the customer. One way it could be helpful to the company is if a new product is in development and perhaps a sneak preview is posted online. Readers could post feedback on what they think is good or bad about the product. The company could use these good ideas and adjust the product before the final release. The feedback is free so effectively the product is made better at nearly no cost.
</p>
<p>
	It can also be helpful for the customer if they have a question about something and they post it. The question will then be answered and the customer will be happy. But because it’s on a blog and online the question stays online. If another customer has the same question they might find their question has already been answered.
</p>
<h3>The Do-er</h3>
<p>
	The Do-er is a more focused version of the Maven blog type. Rather than covering a broad range of issues The Do-er blog type is more focused on specific topics and issues. The information is written by experts in a company.
</p>
<p>
	This type of blog really shows that the company is up with the play to the users who read it. The posts might also be very cutting edge. The blog will demonstrate to the readers that the employees in the company are doing great things. This also gives the employees a boost of confidence because company has allowed them and often encourages them to post interesting things that they know about to the public. This gives the employees a sense of importance and in some ways it might be rewarding.
</p>
<h3>The <acronym title="Chief Executive Officer">CEO</acronym> Blog</h3>
<p>
	The <acronym title="Chief Executive Officer">CEO</acronym> Blog is a blog where the <acronym title="Chief Executive Officer">CEO</acronym> posts information about the company and relating issues. He or she might release new products or get feedback on various things but the key point is that the head of the company is directly talking to the customers. It removes the barriers and allows customers to interact directly with the head of the company.
</p>
<p>
	The customers benefit by have a direct line of communication with the <acronym title="Chief Executive Officer">CEO</acronym> and the <acronym title="Chief Executive Officer">CEO</acronym> benefits by receiving feedback from the customers directly and not having it filtered through several managers before reaching him or her.
</p>

<h2>Conclusion</h2>
<p>
	We have learnt that blogs can be a very powerful tool in business. It’s cheap, simple and can be very effective. A blog can be a great way to form excellent relationships with your customers but there are also great company benefits too. You can keep employees happy by showing them that they are intelligent enough to post information under the company name and the public. You can gain better feedback on products by allowing comments and discussions to happen.
</p>
<p>
	The six types of blogs outlined, show six different ways and focuses a blog can have, each with different benefits. To make a business blog the most successful you need to decide which blog type best fits your business situation. Which one in your specific case will suit your company’s vision and the customer’s expectations?
</p>
<p>
To finally answer the question:
</p>
<blockquote>
	How would a business use blogging as a customer relationship management tool?
</blockquote>
<p>
	A business would have to carefully look at the pros and cons of each type of blog and come to a decision on which one is best. Then setup the blog and make sure regular postings occur. This is how a business can successfully use blogging as a <acronym title="Customer Relationship Management">CRM</acronym> tool.
</p>
<h2>References</h2>
<p>
	Christopher, C. F. (2005). The Business Blogging Field Guide.<br />
	Retrieved November 4, 2005, from<br />
	<a href="http://www.cerado.com/download/CeradoBusinessBloggingFieldGuide.pdf">http://www.cerado.com/download/CeradoBusinessBloggingFieldGuide.pdf</a>
</p>
<p>
	Christopher, C. F. (2005). Why blogs?<br />
	Retrieved November 4, 2005, from<br />
	<a href="http://www.cerado.com/download/CeradoBlogDatasheet.pdf">http://www.cerado.com/download/CeradoBlogDatasheet.pdf</a>
</p>
<p>
	Creotec (2005). electronic business terms and definitions (glossary).<br />
	Retrieved November 4, 2005, from<br />
	<a href="http://www.creotec.com/index.php?page=e-business_terms">http://www.creotec.com/index.php?page=e-business_terms</a>
</p>
<p>
	Mohammed R.A., Fisher R.J., Jaworski B.J. and Paddison G.J. (2004). Internet <br />
	Marketing: Building Advantage in a Networked Economy (2nd Edition)
</p>
<p>
	Wikipedia (2005). Blog. Retrieved November 4, 2005, from<br />
	<a href="http://en.wikipedia.org/wiki/Blogging">http://en.wikipedia.org/wiki/Blogging</a>
</p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=6gUdEbJd"><img src="http://feeds.feedburner.com/~f/djones_blog?i=6gUdEbJd" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=9WhG4GOA"><img src="http://feeds.feedburner.com/~f/djones_blog?i=9WhG4GOA" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=0dwlyIoK"><img src="http://feeds.feedburner.com/~f/djones_blog?i=0dwlyIoK" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=5JeVqwsI"><img src="http://feeds.feedburner.com/~f/djones_blog?i=5JeVqwsI" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;
Have you ever wanted to start a blog for your business? If you have, this is a must read before looking any further. This white paper which I wrote as part of my degree, will fully educate you on how you can gain more business from creating the right type of blog for your business.
&lt;/p&gt;</description></item><item><title>Processing Credit Cards in New Zealand using Ruby on Rails</title><link>http://www.d-jones.com/2007/3/18/active-merchant-new-zealand</link><category>Ruby on Rails</category><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">djones</dc:creator><pubDate>Sun, 10 Jun 2007 23:11:21 -0500</pubDate><guid isPermaLink="false">tag:www.d-jones.com,2007-03-18:2</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[
            <p>Up until now, New Zealand based online stores using <a href="http://rubyonrails.org">Ruby on Rails</a> had to use Paypal to process credit cards. <a href="http://code.google.com/p/activemerchant/issues/detail?id=20">Today, I'm releasing support for a new gateway</a> to <a href="http://activemerchant.org">Active Merchant</a> which uses a local online payment company called <a href="http://paymentexpress.co.nz">Payment Express</a>.</p>
<p>This has opened up New Zealanders to <a href="http://www.shopify.com">Shopfiy</a>, one of the best web 2.0 applications around.</p>
<p>Up until now, New Zealand based online stores using <a href="http://rubyonrails.org">Ruby on Rails</a> had to use Paypal to process credit cards. <a href="http://code.google.com/p/activemerchant/issues/detail?id=20">Today, I'm releasing support for a new gateway</a> to <a href="http://activemerchant.org">Active Merchant</a> which uses a local online payment company called <a href="http://paymentexpress.co.nz">Payment Express</a>.</p>

<h2>Why Payment Express?</h2>
<p>Payment express is local, which means you can hook your online transactions direct into your New Zealand bank accounts.</p>

<p>
From Payment Express website:</p>
<blockquote>
In NZ we support ANZ, Westpac, National Bank, ASB and BNZ. In Australia we support ANZ, NAB, Westpac, CBA, St George and Bank of South Australia. The Maybank in Malaysia is supported and the Citibank for Singapore.
</blockquote>

<p>Payment Express is also very well used in the NZ industry. Here are just some of the companies using Payment Express:
</p>
<ul>
<li>Trademe</li>
<li>Sony</li>
<li>Farmers</li>
<li>HP</li>
<li>EziBuy</li>
</ul>

<h2>Active Merchant</h2>
<p>
<a href="http://activemerchant.org">Active Merchant</a> is an open source plugin for Rails. It's an "extraction from the e-commerce system Shopify". In short, it makes it super easy for anyone to easily and cleanly make credit card payments from their Rails application.</p>

<h2>Show me the code!</h2>
<p>Enough talk, here's some example code demonstrating how you might go about using the gateway to process credit cards in your application.</p>
<p>
First run this command from the root of your Rails application:</p>
<pre>
 ruby script/plugin install http://activemerchant.googlecode.com/svn/trunk/active_merchant 
</pre>
<p>Now add the appropriate files covered below...</p>
<p><em>app/views/payment/index.html</em></p>
<pre><code>
&lt;% form_tag :action => 'process' do -%>
	&lt;label>Number&lt;/label> &lt;%= text_field :credit_card, :number %>
	<small>E.g. 4111111111111111</small><br />
	&lt;label>First Name&lt;/label> &lt;%= text_field :credit_card, :first_name %>
	<small>E.g. David</small><br />
	&lt;label>Last Name&lt;/label> &lt;%= text_field :credit_card, :last_name %>
	<small>E.g. Jones</small><br />
	&lt;label>Type&lt;/label> &lt;%= select :credit_card, :type, ['visa', 'master'] %><br />
	&lt;%= date_select :credit_card, :expiry, :discard_day => true,
                                                                :start_year => Time.now.year,
                                                                :end_year => Time.now.year + 10 %>
    &lt;%= submit_tag 'Process' %>
&lt;% end -%>
</code>
</pre>
<p> The view is very simple. Just gather the information about the users' credit card...</p>

<p><em>app/controllers/payment_controller.rb</em></p>
<pre><code>
class PaymentController &lt; ApplicationController
  
  require 'money'

  def process
    creditcard = assemble_credit_card

    if creditcard.valid?
      gateway = ActiveMerchant::Billing::PaymentExpressGateway.new(:username => 'your_username',
                                                                :password => 'your_password')

      response = gateway.authorize(1000, creditcard, {:reference => 'This weeks rent'})

      if response.success?
        result = gateway.capture(1000, response.authorization)
        
        render :text => response.inspect
      else
        raise StandardError, response.message 
      end
    end
  end

private

  def assemble_credit_card
    ActiveMerchant::Billing::CreditCard.new(
      :type       => params[:credit_card][:type],
      :number     => params[:credit_card][:number],
      :month      => params[:credit_card]['expiry(2i)'].to_i,
      :year       => params[:credit_card]['expiry(1i)'].to_i,
      :first_name => params[:credit_card][:first_name],
      :last_name  => params[:credit_card][:last_name]
    )
  end

end
</code></pre>

<h2>What Now?</h2>
<p>During the process of developing this gateway we've been using a Payment Express test account. If you're looking at adding credit card support for your Rails application then I'd suggest you <a href="http://www.paymentexpress.co.nz/apply/apply.aspx">sign up here for a test account</a> so you can get your application under way! Make sure you select "Development Account" on the pricing plan.</p>
          <div class="feedflare">
<a href="http://feeds.feedburner.com/~f/djones_blog?a=9pKVXecj"><img src="http://feeds.feedburner.com/~f/djones_blog?i=9pKVXecj" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=jNmJ5EnZ"><img src="http://feeds.feedburner.com/~f/djones_blog?i=jNmJ5EnZ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=AkzjtWgo"><img src="http://feeds.feedburner.com/~f/djones_blog?i=AkzjtWgo" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/djones_blog?a=brdml1JI"><img src="http://feeds.feedburner.com/~f/djones_blog?i=brdml1JI" border="0"></img></a>
</div>]]></content:encoded><description>&lt;p&gt;Up until now, New Zealand based online stores using &lt;a href="http://rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt; had to use Paypal to process credit cards. &lt;a href="http://code.google.com/p/activemerchant/issues/detail?id=20"&gt;Today, I'm releasing support for a new gateway&lt;/a&gt; to &lt;a href="http://activemerchant.org"&gt;Active Merchant&lt;/a&gt; which uses a local online payment company called &lt;a href="http://paymentexpress.co.nz"&gt;Payment Express&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This has opened up New Zealanders to &lt;a href="http://www.shopify.com"&gt;Shopfiy&lt;/a&gt;, one of the best web 2.0 applications around.&lt;/p&gt;</description></item><feedburner:awareness xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://api.feedburner.com/awareness/1.0/GetFeedData?uri=djones_blog</feedburner:awareness></channel></rss>
