Thursday 26 November 2009

It is times like this I love RoR

Declarative_authorization and Authlogic - just the best. That would have taken me days - as it is it only took as long as it did because upgrading RHEL5 to Ruby 1.8.7 (which DA needs) was such a pain.
Works like a dream in my little test set up - now to make it work on the real thing.

Wednesday 25 November 2009

Riiiight ....

Well that was a monumental PITA.
In the end upgrading Ruby caused the gem install to go all haywire. In the end the easiest thing was simply to reinstall all the gems - so now I have two loads of the same gems on my server. Why do I think this is a bad thing and going to come and bite me on my arse someday...?
Of course if RHEL 5 had had the right install of Ruby ...

Tuesday 24 November 2009

Grrrr - upgrading Ruby

Why is the YUM package stuck on 1.8.5? Want to use Declarative_Authorization but it needs Ruby >= 1.8.6. Tried to upgrade but the last thing you must do is to end up with two installs of Ruby on yr server. And the last thing I ended up with was ...
That way confusion and madness lie.
So I hope I have managed to uninstall one and upgrade the existing version to 1.8.7. Of course all of this would have been a whole load easier if YUM had had the right package ...
Oh sod it.
Hasn't worked - need to pass it a path I am guessing in the ./configure - path="/usr/bin" I am guessing ...

UPDATE: No - make that prefix=/usr
I read somewhere that that was a no-no and Linus Torvald himself will come and kick my arse for doing that. Hope not.

Authlogic

Loving it.
Authentication in zero time - and some quite nifty tracking features right out of the box.

Just followed the tutorial - plus the ever-brilliant Ryan Bates on
Asciicasts and it all worked first time. Have to love it.

Now to work out authorisation...

Thursday 12 November 2009

Nested polymorphic associations - 2

Have fought through the undergrowth and am in a clearing - and I can see the way out.
The most important thing is to pay close attention to what
rake routes

tells you. And if you have a job_scannings_batches path - remember to give the objects in the correct order. Rails may be smart, but it isn't that smart.
Have a kludge in place to get the second layer of nesting to work - not sure it is very elegant, but it works. I get the name of the polymorphically associated class and use that to do a custom search
(ie @batchable.Class.name). I can't help but feel I should be able to do it using an association of some kind. However it works so ... (but it feels bad)

Wednesday 11 November 2009

Nested polymorphic associations

My ears are bleeding ...

Slowly getting there, but lordy-oh-lordy nested polymorphism is tricky stuff : things like this
form_for [@job, @batchable, @batch] do |f|

in order to generate the correct form for a URL like this
/jobs/18921/scannings/1/batches/1/edit

We have batches which are either photographic, or scans. They belong to jobs. There is a polymorphic relationship (batchable) between them all.
Then nest all of that inside the jobs so that you only get the batches that belong to a particular job. Fun for all the family...

Wednesday 4 November 2009

command line svn

Working from home and it is a PITA to get ZigVersion to work so use command line SVN. Most of the time it is fine, but it is a bore when you create a new model and have to add a whole bunch of files by hand.

Some searching found this unix beauty
svn st | grep ^? | awk '{print $2}' | xargs svn add

Haven't tried it - but it looks very sweet indeed.
Tip o' the hat to John Duell on Internet creators

Sorting an array - sorted

Had a case where calling in an associated class, but don't seem to be able to determine how Rails sucks the data out of MySql - so have had to sort it after the fact.
This little bit of code seems to do the trick

@jobs.sort! { |a,b| b.id <=> a.id }

This is descending - if you want ascending then swap over b.id and a.id.
Don't ask me what is actually going on - but it works