Archive for August, 2008

Love Endless

Wednesday, August 20th, 2008 | Poetry | No Comments

Thinking of you comes so easily
It’s strange to think that it comes so purely
Love flowing through me as though I were a river
Feeling into the emotion ensures a subtle quiver

Holding you in my arms, your eyes playfully sparkle
The universe unveils it’s magic, the result is remarkable
Existence just stands by as time stops on a dial
And all creation marvels at the beauty of your smile.

Cogito, ergo sum.

Saturday, August 16th, 2008 | Anything | No Comments

I think, therefore I am.

- René Descartes

Getting Lightbox Gone Wild to work with Rails

Sunday, August 10th, 2008 | Code | No Comments

Having to implement a good modal dialog script with Rails on the latest project at work, I came across a bit of an issue when making POST AJAX requests. This was due to Rails having some nifty security features, albeit in the name of authenticity tokens. This is basically to prevent CSRF attacks (read more about that here: Wikipedia

Each time I made a request via an AJAX POST request, without the token - Rails would give me a funky little error, something like “you fail at making AJAX requests”. To get around the issue, I asked for some help at the Railsforum er… forums, and got a prompt reply- I needed to add the authenticity token to my requests. This is how I did it:

First and foremost, we need the authenticity token available for javascripts, so, added to my _javascripts.html.erb partial, was this piece of code:

<%= javascript_tag “var AUTH_TOKEN = ‘#{form_authenticity_token}’;” if protect_against_forgery %>

We’re only adding it if the security feature is enabled.

Next, we take a look at the Lightbox Gone Wild code, and from line 124, we see this:

var myAjax = new Ajax.Request(
this.content, {
method: ‘post’,
parameters: ”,
onComplete: this.processInfo.bindAsEventListener(this)
}
);

We need to update this to reflect our new auth token. To do this, update it so that it looks like below:

params = (AUTH_TOKEN) ? ‘authenticity_token=’ + encodeURIComponent(AUTH_TOKEN) : ”;
var myAjax = new Ajax.Request(
this.content, {
method: ‘post’,
parameters: params,
onComplete: this.processInfo.bindAsEventListener(this)
}
);

Note the additional params variable. We add this to ensure the authenticity_token variable is added to all outgoing requests if it’s been enabled. So go ahead, start making those AJAX POST requests via lightbox!