The Hitchhiker’s Guide to Ruby On Rails Galaxy

Records of my voyage through RoR Galaxy

Archive for February, 2008

In Rails 2.0, use attribute pairs to create add and remove column migrations.

Posted by arjunghosh on February 14, 2008

We see a very useful feature in Rails 2.0 as defined in Changeset 7422, where now we can generate migration for adding and removing columns by directly passing attribute:type pairs to the migration generator.
Now for example, we need to add a column called ‘dept’ to students table where the model will be called ‘Student’.
Now previously we used something like:-

script/generate migration add_dept_to_student

Now in case of new better way of writing migration in Rails 2.0, we write it as follows:-

script/generate migration AddDeptToStudent dept:string

Here the migration name AddDeptToStudent holds the key. ‘Add’ specifies the we want to add column(s) and ‘Student’ separated by ‘To’ specifies the table.
Similarly, if we need to remove a column ‘dept’ :

script/generate migration RemoveDeptFromStudent dept:string

Similar to above, the migration name RemoveDeptFromStudent holds the key. ‘Remove’ specifies the we want to remove column(s) and ‘Student’ separated by ‘From’ specifies the table.


Posted in Uncategorized | Tagged: , , | 3 Comments »

:disable_with does not work with Merb

Posted by arjunghosh on February 14, 2008

Beside the known problem of :disable_with killing form_remote_tag AJAXiness, I recently faced another one – namely that it seem :disable_with for Submit_tag does not play well with Merb . In the current project I am working, we decided to use Merb for file upload as it is a very fast and lightweight server which was originally built for efficient file uploads. Well, I thought of using the :disable_with option in submit_tag for some fancy submit button state to indicate that the current form is submitting. Well at the first look everything seem fine, and the form got submit. Then after more testing, we found that picture upload in that form via Merb was not working. After some hectic debugging(as :disable_with is the an obvious suspect), we concluded that :disable_with was the culprit. Well the solution to this was a crude hack where we are calling a javascript in the :onsubmit to accessing the submit button and changing the style while the form gets submitted. Well thats what I can think of in short notice. If anyone has a solution for this, please feel free to tell.

Posted in Uncategorized | Tagged: , , , , | Leave a Comment »