OpenID goodness

June 24th, 2007

I really should get back into blogging again so here goes…

After seeing no less than 4 OpenID seminars in 5 months, I wanted to have a go myself.

There are many implemenations now for rails, but after skimming through 3/4 I settled on the most straightward of them.

Dan Webb has written a brilliant quickstart guide to getting your site up and running with OpenID.

After following his instructions and installing the ruby-openid gem, I had a working OpenID registration & login.

Just needs a bit of refactoring now…


User login Etc

November 20th, 2006

Over the weekend I created a user login system for the site. A basic part of any substantial site, as well as a good learning curve task for learning new frameworks/languages.

As per usual I used one-way, salted encryption on password fields, as well as encrypting & prefixing cookie values, in the manner of email:hash-of-email-and-salt to prevent cookie-hijacking XSS attacks.

Some perculiar problems arose however; When encrypting a string (MD5 or .encrypt) and then pre-append more text to it, it would change the hashed value. This became very annoying and prevented me abstracting functionality. When using SHA1 encryption, I encountered another problem where after hashed values coming from a database would have extra escape charactors, similar to the issues with PHP’s magic_quotes.

Filters rock! They’re something I’m not used to in other languages, and even after little use are saving time & code duplication.


RoR Books

November 20th, 2006

For the first few weeks I decided to hold off buying any books in favour of scouring the web for useful tutorials. This worked fine and I got to grips with the basics, however as of last weekend for a week or two I’m internet-less and I ended up with a Mac Mini setup to develop rails with no reference material to fallback on!

So I made the plunge. The two investments I made were “Agile Web Development with Rails” and “Ruby Programmer”, both by publishers Pragmatic Programmer. I heard a lot of buzz about the former of the two, as well as about their publisher, but had never actually read any of their stuff.

I’m pleased to say the books are great! Having worked my way through half of the first in under a week. I feel like i’m no longer in the dark with some of Rail’s finer quirks, and understand how it all works a lot better. The second book is an invaluable reference source, as it covers different (language rather than framework) topics. There is some overlap between the two but not as much as I’d expected.


The joy of InstantRails

October 30th, 2006

After all of the macs i’ve purchased over the last few years breaking within 12-18 months, I decided to hold off before going through the whole thing again, so as a result for the past couple of years: I have used PCs.

I installed a version of InstantRails a while ago, and it sucked. The project folders were in the application bin directory, it required strange commandline quirks to work and due to using my work machine to develop, installing MySQL on the local machine was out of the question.

This last week I reinstalled with a newer copy of the application

And it kicks some serious ass!!

Firstly you get a GUI interface to control the whole environment, from the Apache and MySQL instances, to the rails apps and Mongrel. The commandline works flawlessly now and for the database you get phpMyAdmin goodness.

I have IIS & SQL Enterprise Manager running on my work box which has a helper app running on port 80, causing apache to crash on startup, but since you have direct access to alter .conf files, I was able to painlessly switch apache to run on port 81.

If you’re cutting your rails on windows, this is the best and only option.


MediaTemple commandline rails

October 30th, 2006

I know I know, it’s bad form to develop on a live machine. But when you’re new in town, with no localhost setup for development, it seems acceptable to start with.

But much as I love their easy to install rails container gridservers, they can’t do certain things, such as the scaffold command in my previous blog. Hopefully this will be fixed as the gridserver product gets refined.

Only 1 of 4 support responses from MT was anything near trying to tackle the issue raised in my support query… *shrug*

Advice: Get your localhost version setup as soon as possible, as certain features on the live gridserver won’t be available to you. Only populate the live site when you’ve scaffolded and got a working local copy.


Two steps forward, one step back

October 26th, 2006

I’m getting a rails error when trying to setup rails scaffolding. Below is the SSH output explaining the problem:

devr.co.uk@cl22$ script/generate scaffold companies
...
Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

I submitted a ticket to MT last night and got a response earlier today giving me instructions to create a basic php connection to the database. :-(


Early steps

October 26th, 2006

So basically my free time in the last few days has consisted of reading various ruby/rails related tutorials & documentation. Slowly, very slowly, i’m starting to encounter less random errors, and feel I understand the RoR a bit better.

One really useful feature of MediaTemple hosting is they give you a x.gridserver.com web-address, seperate from your main account domain. This is great for allowing the main domain to keep a placeholder page.


print_r in ruby

October 23rd, 2006

Having used PHP a lot, I love the print_r function (and am even fonder of Zend::dump).

I was slightly surprised to see ruby has no direct equivalent. After asking around, it appears there are some options available…

lib/pp was pointed out, which stands for PrettyPrinter, for use printing data structures. Similar, but not quite.

Some googling later, I came across a third party code-snippet that supposedly ports more accurate print_r behaviour.

Update: Thanks to Lee, I now also know about .debug.

Also, by simply including the line require "profile", automatic execution-profiling kicks in! This can also be used at the command line by typing script/profiler 'foo.bar'.

Also of interest seems to be raise foo.inspect.


RoR - Hello world

October 23rd, 2006

Getting to the stage of creating a basic hello world application in rails was quite confusing for someone used to PHP and the like. Rails seems extremely biased towards the command line (Symfony is a post-rails PHP project aiming towards similar), and local machine development.

After two or three false starts and confusion over dissappointingly vague/confusing error messages, I’m now at the stage of having an rails install locally for development, as well as an online version. –woo!


Move to MediaTemple

October 19th, 2006

All of this talk of Ruby/Rails over the last few months has finally caught my interested enough to get on and start something using this new myth-shrouded technology.

We’re trying MediaTemple, as not only do they come highly recommended, but also seem to have jumped to the forefront of ruby hosting with their gridserver scheme (not to mention the 20% discount voucher banded around the GeekUp list).

This blog will chart our progress not only with building devr up from nothing, but also, progress made with rails itself and learning a new and somewhat daunting language & framework.