Archive for December, 2005

Off Topic: Songs of the Year

Wednesday, December 14th, 2005

Rish may think it’s been a bad year for music but I’ve probably spent more on choons this year than since I used to hang about in Arcade, Selectadisc and Crash, asking the staff if they know the one that goes “squiddley squiddley doot doot doot with the breakbeats, eyetalian pianner and chunky bassline” (of course, they always knew what I meant).

My top ten, in reverse order, works out like this:

10: Big City Life – Mattafix. Annoys me now but I liked it at the time.
9: I predict a riot – Kaiser Chiefs. Best band name I’ve heard in ages.
8: My Doorbell – The White Stripes. Even though she can’t drum.
7: Wake me up when September ends – Green Day. In Eyeraq.
6: Dirty Harry – Gorillaz. Fair play Mr Allbran.
5: Hung Up – Madge. As I said elsewhere, her first decent record since 1989.
4: Galvanise – The Chemical Brothers. I’ve heard it too many times but it’s a great record.
3: Welcome to Jamrock – Damian Marley. Apart from Cornwall, Middlesex and Surrey y’all.
2: Your missus is a nutter – Goldie Lookin Chain. Last week she went out on a binge, got off her tits and showed the bouncers her minge. Life in Great Britain.
1: Dare – Gorillaz. It’s great when you’re straight. Yeah!

Christmas Break

Wednesday, December 14th, 2005

I’m off to the other side of the world over Christmas, so no updates for a couple of weeks. Have a good one; here’s to more adventures in Rails next year!

Update on the web service scaffold

Wednesday, December 14th, 2005

I’ve tracked it down to my URL rewriting.

The scaffold calls http://somewhere/service/invoke?service=something&method=whatever

However, the failure is method is nil – therefore I reckon my URL rewriting code is somehow chopping up the query string and therefore the method part (and maybe even the service part) is not getting passed through.

Now I know where to look, I can put this back on the shelf and do some paid work!

Changes in 1.0

Wednesday, December 14th, 2005

Well, one of the changes I detailed below has been included. The SQL Server database adapter knows how to deal with GUIDs (uniqueidentifiers).

However, the issue with booleans has not been dealt with – looking at the code I reckon the fault is with the member_type(name) method – which looks like it ought to belong to ActiveRecord::Base, but I cannot find it.

Nope – looking again, it looks like each_member may be the source – StructuredType (extends BaseType) defines each_member and calls canonical_signature_entry for each column, passing a class and an index. If the class is not a hash or array it asks canonical_type to figure out the type name. If that is supplied with a symbol or string it calls symbol_name, if not it calls class_to_type_name. Both of those look like they are doing what is expected of them. So do we have to go back to the database adapter (reporting the wrong type in the first place)? Again, that looks OK (when bit then :boolean) … still cannot figure it out – my kludgey fix will have to stay for now.

Plus the change in action_controller/request.rb still needs to be manually applied (as well as changing myapp/config/routes.rb to recognise service_wsdl instead of service.wsdl.

And the web service scaffolding still fails (scaffold’s method name is nil).

I’ve got some Delphi to get on with today, so it will probably have to wait till next year.

Rails hits 1.0

Wednesday, December 14th, 2005

Congratulations to DHH and everyone involved.

Time to uninstall all my gems and reinstall them (as I seem to get horrible problems if I have multiple versions installed at once).

Calling Stored Procedures from Rails

Tuesday, December 13th, 2005

I know DHH thinks this is not the Rails way, but I’ve got an urgent deadline and the stuff that the stored procedure does is 1) well tested and 2) very complex.

So I need to call it, to get this stuff done in time.

Afterwards I will wrap a unit test around it (that’s a story for another time) so I can reimplement it in pure Rails, but for that to happen as it should, I also need to get the webservice stuff working (so the logic currently tied up in the stored procedure is accessible to the outside world) and rewrite parts of the desktop application to call the webservice instead of the proc. So a bit of a way off yet.

Anyway, to call a stored procedure in Rails I used the following:

sql = "declare @result int \n"sql += "declare @some_value uniqueidentifier \n"sql += "exec @result = my_stored_procedure @input1 = 'hello', @input2 = 'world', @output = @some_value output \n"sql += "select @result\n" # change this to select @some_value if you want to access the output parameter

result = connection.select_value(sql)

You could probably change the last line of the SQL to select @result, @some_value and use select_all to grab the results if you need to.

Anyway, this is the equivalent of what I would do in Query Analyser – declare some variables for storing stuff, call the proc (using @result to store the return value) and then select the values I am interested in to take a look at them.

However, sometimes it worked and sometimes I would get a “cannot perform this object when the dataset is closed” – looking at the stack trace, it appeared to be coming from the ADO Recordset itself.

Why? There seemed to be no reason for it, until my colleague Nick had a revelation. ADO allows a single Recordset object to contain multiple Recordsets (excellent class naming there Bill). When you send a compound statement via Query Analyser, it splits the actual recordsets into the “data pane” and various messages into the “messages pane”. However, in ADO the messages sometimes get sent back as a recordset. Therefore, Rails was trying to read a “recordset” containing “2 row(s) affected” when the actual data it was interested was in the “next” recordset. As I wasn’t sure if I could get at the underlying Recordset, and I didn’t really want to, I was a bit stumped. But Nick came to the rescue again – adding the line “set nocount on” as the very first statement, before the declares, seemed to solve the problem. Basically, we were telling SQL Server to suppress the messages and it seems to work.

Of course, there will be some configuration somewhere, when it goes live, that will screw it up – so I need to start copying that proc into Rails as soon as.

Sessions idiocy

Thursday, December 8th, 2005

I reckon my session weirdness yesterday was entirely down to the fact that I had been running the same application in both production (within IIS) and development (within WEBrick) mode on the same machine.

I’ve altered my environment files (both production.rb and development.rb) to store their files separately, so at least I get some indication of what is going on. Simply add the line:

ActiveController::CgiRequest::DEFAULT_SESSION_OPTIONS[:tmpdir] = "C:\\Temp\\Ruby\\Dev"

obviously switching Dev for Prod in the alternative case.

I also need to clear out all session files on my drive …

C:cd del /s ruby_sess.*

because for some weird reason the interaction between the two environments means that it spews out session files all over the shop – I’ve found them in C:\Windows\Temp, C:\Temp, C:\Documents and Settings\username and C:\Documents and Settings\username\Local Settings\Temp. The latter one is a hidden folder so Windows Search ignores it by default (which had me stumped for a while).

More on FastCGI for IIS

Wednesday, December 7th, 2005

I actually bothered to read the Readme for FastCGI today (it is included in the source package, not in the binaries). I’ve not taken a proper look at this so I don’t know what effect it may have.

Some of the Path Info rewriting may be down to IIS impersonation:


For authentication to work properly in all instances, you MUST check the ‘Check that file exists’ checkbox, this has the unfortunate side effect of breaking path_info values.

Likewise, under your .fcgi key there are some more options to supply:


StartServers REG_DWORD 5
IncrementServers REG_DWORD 2
MaxServers REG_DWORD 25
Environment REG_BINARY
(newline deliminated, null terminated, for adding additional
environment variables ie. PHP_FCGI_MAX_REQUESTS=25)
Filter REG_DWORD 0
If set to 1, this fastcgi server will be treated as a FastCGI FILTER.
A Filter server receives the file to be filtered from the web server.
for more information, see documentation at fastcgi.com
Timeout REG_DWORD 600
How long extra servers (number above StartServers) are kept alive
before being terminated

It’s the first three that are the important ones. This allows FastCGI to start multiple RubyW processes to handle each incoming request (as each process handles a single request at a time). The Environment option is to allow arguments to be passed to the ruby processor but I’m passing them through the Args key. Which of course doesn’t work for the -e production option.

So get rid of your -e production and instead, create the Environment key (as a REG_BINARY) and put RAILS_ENV=PRODUCTION. A quick tip, using the XP version of RegEdit – editing a binary key gives you a text area with three columns – the decimal, hex and text. You cannot type in the decimal, but you can put in your hex values into the hex column. What is blatantly not obvious is that you can also type in the text section. So I wasted five minutes of my life looking up those values when I didn’t need to.

However, I’ve set the Environment key to “RAILS_ENV=production” (52 41 49 4C 53 5F 45 4E 56 3D 70 72 6F 64 75 63 74 69 6F 6E 0D 0A 00) and it makes no difference – still running in Development mode. I could just edit environment.rb I suppose.

Incidentally, the Bind-Path is the named pipe that FastCGI uses to communicate, as I suspected.

If you want more than one rails application on a single server then you add new keys (instead of .fcgi, use .myapp or something like that). You need to rename your dispatch.fcgi to match the newly chosen key, create the FastCGI mapping in IIS and set up the application and args for your new file extension.

*STOP PRESS* I take it all back. The Environment key is working fine and I was being a tit.

David Heinemeier Hansson

Tuesday, December 6th, 2005

Mr Hansson emailed me today to point out my basic inability to see the blatantly obvious. There is a guide to submitting a patch right on the main page of the Ruby on Rails Developer site.

Bugger, that means setting up Subversion on that Windows box.

Aarrrghhh!!

Monday, December 5th, 2005

I’m not having a good day.

I’m busy updating my site to use Rails in its entirety. I need to store some values in sessions – simple, think I.

session[:booking_id] = booking.id

will do the trick.

Yet every time I navigate to the page that does the following

booking = Booking.find(session[:booking_id])

the application bombs out with a cannot find Booking with a null ID.

Eventually, I look at the C:/Windows/Temp folder on the machine running WEBrick. And every single request from Camino is starting a new session! No wonder I cannot access the data I stored in there!

I have no idea why this is happening – everything looks fine in Firefox (Windows) and Safari (Mac). A quick test in IE 6 (Windows) shows it working there as well (although I can’t find the session file that WEBrick created?!?

This is made even worse by the fact that Safari no longer opens my favoured home page after a recent security update.

Arses. It’s just happened with Safari now. Or has it? Ruby Session files seem to be appearing in both C:/Windows/Temp and C:/Documents and Settings/rahoul.baruah/Temp … which is the correct one? And would it help if I just switched to ActiveRecordStore?