Loud Thinking

I'm not lazy at writing neither I'm bad. But I do not have my personal blog! Because I wont be updating it much! Developing a REST API on top of MyOwnDB was our prime decision to make it integrate able to a number of products/services. And that way, we want to be the memory of Web 2.0! We've been working with the REST API for sometime now and it was a leap from a concept to its application to MyOwnDB within the Rails framework. We had to make many interesting design decisions and for that, I explored top ten REST API's available including Twiter, Google, Flicker and many more.

A step forward

We were looking at the engines plugin for a while and despite all the flame wars around it, Me and Raphael were somewhat convinced that it would be needed somehow in future. I kept trying installing it but failed. So a little context here, we ported our application from Rails 1.2 to Rails 2.02. And it was this version which we "freezed" under the vendor directory. And installing engines plugin on that version was failing. From my past development experiences, and from observing some colleagues for a while in my career, I've a nature of being very lean and mean about things.

Accessing temlpate variables in tests

In your tests, you can easily access variables defined in your templates as:
and here's a concrete example:

Upgrade to Rails 1.2 notes

As I was looking to upgrade applications to rails 1.2, I wrote down all changes I had to do, and post those here in the hope it can be useful to anyone. I have skipped rails 1.1 for some apps and upgraded from rails 1.0, so some (all?) of the points could be from differences between rails 1.0 and 1.1. The first thing is that apparently the name of model classes have to be named very precisely, and there's now a check to see the class was loaded correctly. This caused a problem for the class I had defined in the file app/model/user2address.rb.

Mass mailing with active mailer

So, you have plenty of users, and you want to notify them of a significant update. You have all recipient emails in you database, and the corresponding ActiveRecord models. Rails also provides the nice ActiveMailer tool. Writing a script using all your existing infrastructure seems the best solution, and it's also how I wanted to send an anoucement to MyOwnDB subscribers. There are, however, two points that you need to take into account:
  • you can't simply loop over all emails, and for each address open a connection to the SMTP server.

Some tricks to use S3 in your web application

After the post on my dojo.io.bind experience, here's what I learned in using S3. I'm using the S3 library for Ruby published by Amazon.


When you save an entry with a file attached in MyOwnDB, the Rails action handling the form checks the size of the file. If it is within the limits allowed for the account, it saves the information needed locally in the database (let's say in the table "files"), and then saves the file on S3.

File uploads to Amazon S3 the AJAX way thanks to Dojo

File uploads are finally deployed! You can now specify in MyOwnDB that a detail of your entity is of the type "file". This will let you attach a file to an entry, and subsequently replace or delete it. This required some changes in the application, more specifically in the way the forms are submitted back to the server. For a file upload to work fine, you have to send it with the enctype attribute set to "multipart/form-data". But that's not all! You cannot just serialize the form in javascript like you can do with other input types because you cannot access the file from Javascript.

Sending HEAD requests using Amazon's S3 Ruby lib

After some usage of Amazon's S3 storage service from Ruby, I'm quite happy with the result obtained.

Testing Rails controllers communicating with external web services

As I was writing the code to accept payments through Paypal for MyOwnDB, I kept wondering how I could write functional tests to validate it. All those methods initiate or react to communications with Paypal, and although there's a sandbox available, you cannot predict the id assigned to the transactions and that must be returned to Paypal (see below for how this validation works)., This clearly limited the scope of the tests I could write.

Google sitemap for Ruby on Rails website

I was building a Google site map for http://www.myowndb.com using their generator (in python). Using the generator is very easy: just edit the config file according to the comments included the example. You can configure the generator to analyze access logs of your webserver to extract URLs to put in the sitemap.
Syndicate content