Archive for July, 2006

Rails search in 5 minutes

Monday, July 10th, 2006

I got to the point of needing to add search to the CMS I’m working on, so did a quick google search to see if there was any existing help for doing search in Rails. Up popped a result on the Rails Wiki, TextSearch.

After reading through, it was a basic module for adding search code to the Rails models - nifty. Reading further down, the strengths of the wiki came to the fore as more people made suggestions on implementation and functionality, until at the bottom we get Nate McNamara’s expanded version that supports a simple query language.

I saved the code, added the two lines to my news post model and threw together a quick search controller. Within five minutes I’ve got a working news search, that can very easily be expanded to other areas (normal content, articles, etc.).

With all this initial work basically done for me, I can now spend my time looking at things like aggregation to see if I can search across multiple fields and otherwise fine-tuning the code to my own needs.

Rails and its community make life so much easier!

Boff!

Monday, July 10th, 2006

Can’t believe the disgrace of Zidane last night. I can only hope Materazzi said something seriously bad to him to go at least part-way to explaining such an insane attack.

Anyway, Cute Overload have a little guy that Zidane was obviously learning from. Check it out!

Creativity in education

Friday, July 7th, 2006

I’ve just watched a video linked to from WeBreakStuff’s ‘weekly inspiration‘ and it truly was inspiring. It was a talk by Sir Ken Robinson on creativity in education, the gist of it being about how education stifles creativity to the point where most children have lost their creativity by the time they leave school.

It’s an excellently-delivered talk, with plenty of humour to go along with some very good points. It got me thinking back the few years to when I was in school - I was pushed out of doing an Art A-Level (as an extra, so wouldn’t have meant one less ‘academic’ subject). Luckily I was quite good at the academic stuff too, but it was a setback to my more creative, arty side.

Anyway, watch the video, it’s great.

Double standards

Thursday, July 6th, 2006

Browsing StyleGala this afternoon, I spotted a link to an article about the rise of awareness in corporate Britain of the need for accessible websites. ‘Great news’ I thought, clicking the link and reading the article.

It basically seemed to be a bit of PR for some company called Tridion (can’t say I’d ever heard of them), who make content management software for large corporations and have partnered with Reading Room, who are going to use Tridion’s latest stuff to make accessible sites.

That’s all spiffy, but I searched for Tridion’s site to see what it was they were doing to make these marvelous accessible websites and found a website done partially in tables, that fails the Section 508 and WAI accessibility tests. I can only hope it’s Reading Room that have the accessibility expertise and that they’re just relying on Tridion for the back-end stuff.

Why am I picking on these people? I realise this post might seem a bit harsh, singling out a company when there are plenty doing far worse, but from what I can see they’ve decided to put themselves out there as people making these great accessible websites for organisations like Christian Aid. That’s fine - PR is PR and I have no problem getting a bit of free publicity by providing comments on new regulation/standards (the apparent initial point of the article) - but if you’re going to do it, at least cover the bases. If you’re going to announce to the world this great new partnership making accessible websites, make damn sure your own website passes basic accessibility tests (working properly in more than Internet Explorer would help too).

There seem to be plenty of people claiming standards-compliant, accessible design these days while not actually quite living up to it. Just yesterday I read a post on 456 Berea Street about how 71.8% of CSS Reboot participants failed XHTML or CSS validation (or both). For an event meant to showcase standards-based design that’s pretty poor (though to be fair to the organisers, it’s not something they canreally control until the launches happen and even then it’d be a LOT of work to go weeding out any and all non-compliant sites).

It’s not always possible to adhere 100% to standards, especially as the standards aren’t always cut and dried, but stuff like avoiding table-based layout and providing alt tags for images are a seriously low entry point that many still aren’t managing.

Rant over :D

The Fast-CGI difference

Wednesday, July 5th, 2006

Having got my Rails CMS working under CGI last night, this morning I switched it to dispatch.fcgi and it really does make a serious speed difference!

Running with dispatch.cgi the app was pretty slow, taking a few seconds for each page to load, while using Fast-CGI it’s near instantaneous. I’d never actually tried using normal CGI as everyone says you should use FastCGI and now I see why. So, use Fast-CGI! :D

Deploying a Rails app…

Tuesday, July 4th, 2006

Not as easy as you’d imagine.

Today I tried moving my Rails-based CMS code onto my host’s server so I could combine a bit of PHP code with it until I get time to re-write in Ruby (image manager plugin for XINHA). Having run rails on the server to create a default Rails directory structure, I then uploaded the /app, /config, /lang, /lib and /public folders to add the application code and settings, changing the config files for the server DB and .htaccess and dispatch files for running on the site5 server.

Unfortunately that’s as far as I’ve got so far - the Rails app won’t start, logging “premature end of script” errors in the Apache log. Running dispatch.cgi in the shell (.fcgi gives no remotely sensible errors, so just trying to get normal .cgi working for the time being) gives me this:

/usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/initializer.rb:256:in `send’: undefined method `debug_rjs=’ for ActionView::Base:Class (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/initializer.rb:256:in `initialize_framework_settings’
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/initializer.rb:255:in `initialize_framework_settings’
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/initializer.rb:252:in `initialize_framework_settings’
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/initializer.rb:91:in `process’
from /usr/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/initializer.rb:42:in `run’
from ./../config/environment.rb:10
from ./dispatch.cgi:3

I’ll be honest, I’m still new to Rails and the error doesn’t mean a great deal to me (other than it having decided there’s no ‘debug_rjs=’ method in existence - I’m not using any RJS!). I have a feeling it might be a versioning problem - site5 seem to be running Rails 1.0.0 while I’ve been developing on 1.1.2 so I’ve sent them an email to see if it’s possible to get 1.1.2. Other than that, I’m pretty much stuffed at this early stage of my Rails experience. If any Rails experts happen to read this and can think of a solution, please let me know!

The one thing I do miss from PHP is clear, explanatory error messages at pretty much all times. Yes, it’d sometimes tell you line 34 when the problem was at line 31, but it usually does a very good job of pointing you close enough to the problem and with enough info to quickly track down what’s happening. With Rails I get a page just telling me the application failed to start (it’s in development mode, not production, so there’s no reason not to give more info on what went wrong).

Anyway, I still love Rails from a development point of view - I’ll just love it more if I can get it to work on a live website!

UPDATE: Yup, it needed to be Rails 1.1 - running ‘rake freeze_gems’ on my local install to dump the rails code in /vendor/rails and then uploading that got it working.

A lesson to laptop owners

Monday, July 3rd, 2006

Having practically just burned myself, here’s a (potentially quite obvious) tip for laptop owners - make really sure the laptop has actually turned off before putting it in your bag. I usually set it shutting down, close the lid and start packing up.

I just went to get my laptop out of my bag (4 hours after leaving work) and though my bag felt warm, but was a bit confused as it wasn’t next to a radiator (and really, with the weather we’ve had it wouldn’t be on anyway). Reaching in to lift my laptop out of the pouch built into my backpack is the point I came close to a burn. Seriously. The laptop had failed to shut down (one of those ‘program not responding, end now?’ messages) and in the closed confines of a backpack there was no route for hot air to escape at anywhere near an acceptable rate - cue one VERY hot laptop.

Luckily no damage seems to have been done. It was still running - impressive by itself given it’s been 4 hours since it was unplugged - and has logged back in fine. Here’s hoping I don’t make that mistake again :)

New design time!

Sunday, July 2nd, 2006

Last time I was re-aligning but I think this time it has to count as a re-design. After feeling the urge to re-design the site a few times in recent months but never actually being able to come up with any decent ideas (why is it so much harder to design for yourself?), I’ve eventually plumped for ripping and modifiying the back-end design from the Rails content management system I’m working on.

supersonic feet layout, version 3

The previous design (above) was very much on the minimal side, with no images in the design (unless you count the strip of photos from flickr), even getting listed on Design Melt Down’s Super Clean section. I’ve tried to keep the new design quite simple still, but added a little bit of graphical interest to help things along so there are now four images in the layout (background, the flickr arrow link and rounded box top and bottom).

This new design hopefully has more focus, especially with a move to fixed width (the old liquid layout didn’t always look great at high-res). The content area is cleanly defined in the white box and I think the new placement of the photos works better, especially on the black background.

While the last re-design (re-align) was done with only a very minimal change to the HTML (i.e. the stylesheet did all the work, as is the ideal), this time I have shifted it about a bit, largely to sort out the semantics. The code order now has a nice title-content-menu-footer flow, with the CSS shifting the menu back up to the top for visual placement. As such, people using screen-readers shouldn’t have to listen to a load of junk before getting to the content they’re after, although there’s a link to the menu at the top of the page incase that’s what they’re after first.

More of the site pages should actually look OK with the new design right from the off this time (I never got round to sorting some in the old design) and it seems to work just about correctly across browsers, although there’s an odd right-float-clearing problem in IE (both 6 and 7) that I’ll need to sort out. In the meantime, apologies for the post info boxes on the right not lining up properly if you’re using Internet Explorer.

While I’m on the subjct of Internet Explorer (in a round-about kind of way), last week we had our ADSL connection re-graded. We were on a 1mbps line but with ADSL MAX we were now promised 3.5mbps. Well I’ve had a week of at most downloading at 200KB/s (which is roughly 2mbps), but often all the way back down to 70KB/s and with plenty of connection failures, all of which I half-heartedly hoped was just the line settling down and BT playing with things. Until tonight, when I downloaded the Internet Explorer 7 beta 3 and noticed a silly number.

After watching the silly number for a few seconds and my download suddenly being done, it turns out I’d averaged about 450KB/s. As a vague check, I downloaded an album from emusic and got similar speeds, so I now really hope this connection keeps up at this speed (and not just at 3am!).

And finally… I’d love to hear any feedback on the new design, so please do leave (constructive) comments. I know there’ll be problems (already mentioned the right-float thing), but let me know whether you like it or not!

Wow, that was easy

Saturday, July 1st, 2006

I just got around to looking into creating RSS feeds for the news section of the CMS I’m building in Rails, so dug out my still-new Rails Recipes book and was pleasantly surprised to see how easy it was. Obviously, an RSS feed is just XML which is simple to churn out, but Rails’ XML Builder does it all in code and does it well.

The only bit I had to look up was how to get content:encoded and CDATA tags and I now have a basically-working RSS feed with this relatively short chunk of code in the .rxml view template:

xml.instruct!
xml.comment! “generator=\”infinisys/1.0\”"
xml.rss “version” => “2.0″, “xmlns:content” => “http://purl.org/rss/1.0/modules/content”, “xmlns:dc” => “http://purl.org/dc/elements/1.1/” do
xml.channel do
xml.title @site.title
xml.link url_for(:only_path => false,
:controller => ‘news’,
:action => ‘list’
)
xml.pubDate CGI.rfc1123_date(@news.first.created_at)
xml.description h(@site.description)
@news.each do |post|
xml.item do
xml.title post.title
xml.link url_for(:only_path => false,
:controller => ‘news’,
:action => ’show’,
:id => post
)
xml.description do
xml.cdata!(post.content)
end
xml.tag!(”content:encoded”) do
xml.cdata!(post.content)
end
xml.pubDate CGI.rfc1123_date(post.created_at)
xml.guid url_for(:only_path => false,
:controller => ‘news’,
:action => ’show’,
:id => post
)
xml.author h(post.user.firstname + ‘ ‘ + post.user.lastname)
end
end
end
end

TinyMCE doesn’t like pre-formatted text it seems and I can’t really be bothered faffing around, so I’m afraid it’ll all have to be in one ‘column’ for now

Nifty, non?

Sometimes this Rails lark just seems too easy, though luckily I’ve still managed to set myself a few tricky bits with this CMS so I’m not getting complacent (or feeling too redundant) just yet.

Flickr gamma again

Saturday, July 1st, 2006

After flickr finally adding pages to see comment activity on your photos from one place as part of their swish ‘gamma’ re-design, all was looking good.

Then tonight I tried to get back to the ‘create a flickr badge‘ page and found that their information architecture ain’t all that good. It’s taken me eventually searching flickr’s forums in order to get the link to the page I was after, where the link used to be on your main photos page.

Granted, it perhaps didn’t deserve to be on a user’s main photo page all the time as it’s something you only use now and then, but they seem to have gone from always available to extremely hard to find. I tried going through the various drop-down menus at the top of the page; looking at my account and profile pages; I even looked at the page with the link once and didn’t notice it (the Help > Tools page).

It really doesn’t stand out anymore. For such a handy feature, you’d think flickr would want it very easy to find. One reason I didn’t spot it even when on the right page (aside from the link not standing out in the least) is that the Tools page is under the Help section. To me, help sections are where you go for FAQs, support, etc. and not generally where I expect to find application functionality. Yes tools help you, but in a more functional than advisory way.

Anyway, I found it in the end, just a bit miffed at how awkward I found it.