Google ads

October 29, 2007

A bug in Nifty Corners

I'm have been using the latest version of Nifty Corners (NiftyCube) in two sites for some time but one of them, my main Rails site, has been exhibiting a strange bug which I couldn't quite isolate.  Sometimes the page would finish downloading but wouldn't display until either (a) I touched a key or (b) some considerable time had passed.  I decided to ignore it.

But now I'm completing a third site to use Nifty Corners and I'm guessing that the client won't let me get away with ignoring it this time.  I noticed that the problem was at its worst when using the Back or Forward keys as most of the pages on this third site were straight HTML with only a dash of PHP and should display almost instantly.  But there was that five or ten second delay again.  Maybe it was trying to download one last component of the HTML but I couldn't see why that would stop the page downloading.  I decided it had to be Javascript in the window.onload function.

After some digging through Alessandro Fulciniti's very elegant Javascript, I spotted a function AddCss() where he creates a link tag to load in his CSS file niftyCorners.css.  The problem was that the code assumed that the CSS file was in the current folder.  I changed this to specify the folder:

function AddCss(){
niftyCss=true;
var l=CreateEl("link");
l.setAttribute("type","text/css");
l.setAttribute("rel","stylesheet");
l.setAttribute("href","/_css/niftyCorners.css");
l.setAttribute("media","screen");
document.getElementsByTagName("head")[0].appendChild(l);
}

Now I can get on with what I was supposed to be doing this afternoon.  Hope this post helps someone.

August 14, 2007

Converting ASP sites to PHP

OK, here's a quick tip of you're converting some ancient ASP site to PHP.  Did I mention I used to create sites in ASP.  Sorry, it's a bit embarrassing you see...

When changing a site's technology you don't want old URLs to stop working so you'll want each of the old URLs with .asp in them to safely find the new URLs with .php in them. 

So you'll have a URL such as:

http:⁄⁄www.example.com/foo/bar.asp?someid=14&someotherid=apple

and you want it to be:

http:⁄⁄www.example.com/foo/bar.php?someid=14&someotherid=apple

Apache makes this easy.  Just get hold of the .htaccess file in the root folder of your site and add a line to it:

RewriteRule  ^(.*)\.asp(.*)$ $1.php$2 [R=301]

Care what it means?  Didn't think so.

I'll tell you anyway.  It tells Apache to look for a URL that has ".asp" in it somewhere and tell the browser to redirect to a URL that is made up of the bit before the ".asp" plus ".php" plus the bit after the "'asp".  In regular expressions, anything enclosed in brackets, e.g. (.*), can be accessed in the replacement string using $1, $2 etc.

The bit on the end - [R=301] - tells Apache to send a status code of 301 to the browser telling it is a permanent redirect.

Told you it was quick!

PS There are other ways of doing this of course.  You could keep all the ASP files and fill them with individual instructions to redirect to the new URL or you could put the PHP code into the old ASP pages and keep the URLs the same.  If you go one of those routes, you'll need to tell Apache to execute the .asp page as if it's a PHP page.  The line to go into your .htaccess page would be something like this:

AddType application/x-httpd-php .php .phtml .php3 .asp

June 11, 2007

Contribution Manager - Gift Aid software on Rails

Perhaps unfairly, Rails is mainly associated with social networking sites so it's nice to be able to show that it's being used for mainstream business applications.

Contribution Manager (www.contributionmanager.co.uk) is intended for small UK charities to help them with the administration and claim process for Gift Aid.  It has been designed for use by churches and other charities that use contribution envelopes but can also be used by scout groups, music societies, parent-teacher groups and any other small charity.  Pricing is remarkably low as small charities have enough trouble raising funds and won't want to spend their hard-earned contributions on software. 

As it's designed for UK tax laws, it is unlikely to be much help to non-UK charities/not-for-profit organisations but if it could be modified for use in other countries, I'm sure the authors would appreciate suggestions.

June 10, 2007

Domain mapping and Typepad revisited

Last year, I published a how-to on setting up domain mapping with Typepad.  Since then, I have noticed that some sites link to emilyrose.org instead of linking to www.emilyrose.org.  Because of the way I'd set this up, emilyrose.org still links to my ISP's parking page so Technorati, for example, was showing a picture of the parking page instead of a picture of my home page

So, as I'm using godaddy, I've switched on domain forwarding as well but only to forward emilyrose.org to http://www.emilyrose.org.  The CNAME record to then forward www.emilyrose.org on to olddog.typepad.com does the rest of the job. 

This may seem a roundabout solution but it does work. 

May 19, 2007

Social networking is not exactly new

I think I know how this started.  The Guardian G2 editor reads a story that William Wales (aka 'Prince William', an English 'it boy') has joined Facebook and thinks to himself "Facebook - have I heard of that?".  Then Lily Allen (English singer) joins MySpace and he think "I need to get someone to explain this to me".  So some young people are duly rounded up by the technology correspondent and an article appears on the "social networking revolution".  The young people are asked to talk about Facebook, MySpace, Bebo, Twitter and SecondLife.  No LinkedIn.  No Ecademy.  No realisation that 'old' people do it too. 

Social networking has been around a while.  How do you suppose the second and third people to master fire found out about it?  Read a book?  Looked it up on Wikipedia?  I'd guess one of their trusted network told them about it.  Social networking was thriving in pubs when I was a nipper and going pretty strong at the IoD when I was a member there.  Just because there's a way to do it online doesn't make it new.   

MySpace started in September 2003, Facebook in February 2004, Bebo in January 2005 and Twitter in March 2006.  But Linkedin has been going since before any of them and Ecademy since June 1998.  Even a mention of Friendster (March 2002) or Friends Reunited (July 2000) would have given the article a little more perspective.

So I did a test.  I logged into Facebook, set up a profile and then looked for university friends.  Not one.  So I pretended I was five years younger and got a few.  Ten years; more.  But I had to act like a 25-year-old before I found significant quantities.  The same test in LinkedIn showed a much broader cross section, right up my former MD who must by 58 or 59 by now. 

So if you think social networking is leaving you behind, don't just pile into Facebook and start making friends with teenages.  That might not actually be very good for your reputation.  Find out what your friends use and give that one a try instead.  And may I give you a tip; don't just form an online connection with anyone and everyone in an attempt to have more connections than your friends and to prove to them that you're not Billy No-Mates after all.  I'd strongly advise that you stick with people you know and people who are personally recommended to you.  Go for quality over quantity.

April 04, 2007

Mephisto and cyclothymic development

It's always nice to learn a new word and Nikolay Kolev has taught me 'cyclothymic', a personality disorder characterised by bouts of intense activity followed by periods of the complete opposite.  Nikolay associates this disorder with OSS Rails development and it's easy to see his point.  Many Rails developments have set off in a burst of enthusiasm and code marathons followed by a rapid descent into inactivity.  I was involved in one myself - I still don't know where half the development team disappeared to.

Mephisto is one such sufferer.  Rick Olsen has confessed that it's been comatose since the end of last year and the prognosis isn't good.  The 'community' around Mephisto hasn't produced any meaningful documentation yet - and yes, I am one of that community so I am part of the problem - so the product isn't getting the following it deserves.  To pick up on a point made by Justin Palmer, it is still seen as a great Rails publishing tool, not a great publishing tool.

This blog uses Typepad and I have other sites that use Wordpress.  Neither tool is leading edge or even particularly impressive but they both do exactly what they need to do and they do it effectively.  I have no need for more than what they do.  So no, I don't use Mephisto and I doubt that I will for a good while yet.  I hope it pulls through as it's a great piece of software ... but there's more to a successful software project than good software.

It is clear that two distinct and damaging problems are afflicting the Rails world.  Firstly, there is a desire to rework existing applications as Rails applications even if no specific advantage is offered to the end user - for example blogging tools, forum tools, to-do lists and so on.  Secondly, the documentation is then neglected so only fellow Rails enthusiasts can be confident of using the software successfully.  I remember the RTFM responses I got from early Unix vendors but at least there was a manual to read.  RTFSVN is no answer at all.  If these issues aren't addressed by the core team, I'm worried that much of the buzz that surrounded Rails in 2005 will be wasted.

March 05, 2007

Rails, email and multipart/alternative

All of a sudden, I need to produce an HTML email for a client.  Is that the only way it ever happens - without warning?

Having recently bought Chad Fowler's Rails Recipes, a book I would recommend, and having spotted its recipe for Gracefully Degrading Rich-Content Emails, I thought I'd use Rails for this exercise.  The recipe uses the multipart/alternative MIME type which allows you to specify an HTML version and a plain text version within the same email.  If the mail client can deal with HTML it displays that version, otherwise it displays the plain text version.  With more emails being picked up on phones and Blackberries, having a plain text fall back option is essential.

The recipe is #67, if you have the book, but I've found one or two problems.  The code for the controller in the book is roughly as follows:

def multipart_alternative(recipient, name, sent_at = Time.now)
  subject      "Test multipart HTML email"
  recipients   recipient
  from         'Old Dog <olddog@examplel.com>'
  sent_on      sent_at
  content_type "multipart/alternative" 

  part :content_type => "text/html", 
    :body => render_message("multipart_alternative", :name => name)

  part :content_type => "text/plain", 
    :body => render_message("multipart_alternative_plain", :name => name)

end

The problem with this code is that multipart_alternative behaves like any Rails method and, by default, renders the view multipart_alternative.rhtml if it finds it.  So the email generated has the content of multipart_alternative appearing twice and thus messing up the MIME syntax.

There are many possible fixes but I preferred to simply rename multipart_alternative.rhtml to multipart_alternative_html.rhtml and alter the render_message accordingly.

def multipart_alternative(recipient, name, sent_at = Time.now)
  subject      "Test multipart HTML email"
  recipients   recipient
  from         'Old Dog <olddog@example.com>'
  sent_on      sent_at
  content_type "multipart/alternative" 

  part :content_type => "text/html", 
    :body => render_message("multipart_alternative_html", :name => name)

  part :content_type => "text/plain", 
    :body => render_message("multipart_alternative_plain", :name => name)

end

The second problem I discovered is when I tested this on a variety of email tools.  Outlook picks up the HTML version and displays it fine but Google Mail chooses the plain text version instead.  Testing is, as ever, essential.

Rails and Windows, a natural partnership?

I happened to be looking at the stats on a website I recently created for a large well-known IT company (whose name is a three-letter acronym) and was surprised how few of the hits were from Firefox.  It was 96% IE and just 4% Firefox.  When I looked at OS, it was virtually 100% Windows.  Curious, I thought, that's not what I would have expected from an IT company.

So that got me thinking.  I took a look at Feedburner's stats for this blog, which could be categorised a Rails Blog as I rarely talk about anything else, and found Firefox 54%, IE 26%, Safari 11% and Opera 9%.  So I scrolled down expecting to see masses of Macs and yet ... 67% Windows, 25% Macs and 8% Linux. 

So does this mean more people develop Rails applications on Windows than anywhere else?  I strongly suspect it does.

February 05, 2007

"Macs are just smug, preening tossers"

That most savage of TV critics, Charlie Brooker, has poured vitriol all over the Mac advertising campaign with all the spluttering fury for which we love him so much.  More power to you Charlie.

January 29, 2007

Rails and Nifty Corners

Having returned to my Rails application after some months of largely ignoring it, I'm implementing the new design and need to round some corners.  In the past, on non-Rails sites, I've used Alessandro Fulciniti's Nifty Corners and found them very simple and straightforward to use.  Alessandro now has a new version, Nifty Corner Cube, and this is even simpler to implement.

Using Nifty in a Rails application requires a few tweaks of course but the first thing to do is read the main page and grab the ZIP file from the link at the foot of the page. 

There are three things needed to implement Nifty: the JS file, the CSS file and a function call in your page.  As this is Rails, we'll need to do them differently to the way Alessandro describes.

  1. Take the niftycube.js Javascript file out of the ZIP file and put it into /public/javascripts.  Then add it to the list of javascripts you are already including.  For me, this mean adding Nifty to the end of this line:

    <%= javascript_include_tag 'prototype', 'controls', 'dragdrop', 'effects', 'custom', 'niftycube' %>
  2. Take the niftyCorners.css CSS file out of the ZIP and put it into /public/stylesheets.  Although the JS file will try to include this itself, it's not going to find it so you'll need to add it into your main layout file as well:

    <%= stylesheet_link_tag 'niftyCorners' %>
  3. The third element is the Javascript function call to set the corners on your chosen elements.  The standard Nifty method redefines window.onload but we can't do that in Rails so we need to use the alternative method provided, a new NiftyLoad function.  So, to set rounded corners on every DIV that has the class 'infoblock', the call would be:

    NiftyLoad=function(){
    Nifty("div.infoblock");
    }

    This can be positioned in the main layout file but a better place is in the specific view by using the content_for("page_scripts") block.  So:

    <% content_for("page_scripts") do -%>
    <!-- Begin

    ... etc ...

    NiftyLoad=function(){
    Nifty("div.infoblock");
    }

    //  End -->
    <% end -%>

And that's it.  It just works.  Couldn't be much easier, could it?