Amazon

Thursday, February 21, 2008

Tidy Stylesheets in Rails

I came across this blog entry on how to organize stylesheets in Rails. At first I was skeptical, but soon ran into a situation where Peter's suggestion really works well. I had to adapt a few things so that it works with Rails 2.0.x. But overall, I am sold!

Monday, February 18, 2008

New Terminal Tab Script for Leopard

My favorite tool for quickly opening a terminal window to a particular directory under Tiger is Marc Liyanage's Open Terminal Here toolbar script.

Now that I am running Leopard, most times I find myself wanting to open a new tab instead. This enhanced toolbar script fits bill, if I am staring at the folder within the Finder.

But, most of the time I find myself staring at a Terminal window, already in the directory I want the new tab to be in. Switching to the Finder in order to find the folder and then clicking on a toolbar button just doesn't cut it for me.

So, based on Solomon White's work, I came up with a similar Ruby script. Under tcsh, I set up an alias named nt pointing to the script. When invoked without any arguments, the script opens a new tab pointing to the same directory as the current one. If one or more directory paths are supplied as arguments, a new tab is opened for each one, placed into the corresponding directory.

The script works fine for me under 10.5.2. Feel free to download it for yourself. Note that the rb-appscript gem needs to be installed as a prerequisite.

Friday, February 8, 2008

Rails 2.0, Scaffolding 1.x

Despite having tried to stay completely within Rails 2.0, I miss the dynamic scaffolding 1.x provided. So this is how I got it back.

script/plugin install scaffolding
script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination


The reason I had to install the classic_pagination plugin is because the dynamic scaffolding plugin depends on it.

It all works well, except I am noticing that whenever I dynamically scaffold something, I had to restart my mongrel server in order for it to take, which is a bit odd. I don't recall it working that way in 1.x. But, it will do for now.

Rails 2.0, Scaffolding 2.0

I finally took the plunge and upgraded my Rails installation to 2.0.2, the latest as of this post.

I knew from David Heinemeier Hansson's blog that act_as_xxx, paginate, and scaffolding have been relegated to plug-ins, but I did not realize the actual transition would be so rough, as myself and others have come to experience.

I played with the new scaffold generator to see how I might work with it. I came up with the following. I finally decided that I don't like it, and installed the old dynamic scaffolding plug-in (along with the classic pagination plug-in, too). But should you want to stay completely within Rails 2.x, you might find this post handy.

Suppose you want to scaffold the MVC triad for a model named TodoItem. When generating a scaffold you really should supply as many fields as possible. If you supply no fields, the views will be empty, which is pretty much useless.

script/generate scaffold todo_item name:string description:text due_date:datetime completed:boolean


Next, run database migration to get the todo_items table created.

The scaffolded MVC triad will be named TodoItem, todo_items, and todo_items_controller, respectively. Depending on the design for your app, the view and controller names may or may not be appropriate. If not, you'll want to generate your own. For example, you may want the view and controller to be named todo and todo_controller instead.

Then, build up the view and controller you want to keep. You may also create more migrations to modify the database schema as needed. For instance, you might want to add a position column so you can support arbitrary ordering of to-do items.

When you are done, if you have been working on customizing the scaffolded view and controller, you need not do anything else. However, if you've generated and built-up another set of view and controller, you need to destroy the scaffolded ones. But, you want to keep the model. So you'll need to execute the following:

script/destroy scaffold --skip-migration todo_item


The --skip-migration option ensures the migration script that was generated by the scaffold generator isn't deleted.

Now, some may ask why don't I just rename the files. Yes, I could do that. But that seems more troublesome to me, as you will have to change the view directory name, the controller file name, the controller class name, and edit the config/routes.rb file.

Instead, I believe a real solution would be to add the option to specify the controller name back into the scaffold generator. Adding the option to allow the scaffold generator to work off an existing model would be a nice refinement, too.

But, when it's all said and done, I still miss the dynamic scaffolds in Rails 1.x. If you feel as I do, you can read my next post, which will outline how to get the old dynamic scaffolding to work within Rails 2.x.

Wednesday, February 6, 2008

Outsourcing Chronicles 001

I am a corporate developer by day. I write web applications for the company I work for, serving the business needs of their customers.

I have been working with .NET and ASP.NET for the past 5 years or so. It has been an enlightening time.

Prior to that, it was VB, ASP, and VBScript for about 3 years. Boy, were those the dark ages!

Anyhow, my career took a different turn early last year, when a major re-org took place. I mean, re-orgs happen all the time. I've survived quite a few. Why was this one different? Well, it was different because outsourcing was involved.

Now, I am going to define two terms: outsourcing and offshoring.

Outsourcing means a business hires a bunch of oversea workers as consultants and assigns somebody from the domestic office to manage them.

Offshoring, on the other hand, means a company sets up a branch office overseas, hires a bunch of overseas workers as employees and assigns someone to manage them. This person is co-located with the new team.

Well, I am referring to the former. Over the years I've worked at this corporation, I have seen heads get trimmed for one reason for another. But the heads weren't replaced. We were told to make do with what is left.

Now, however, the company is trimming domestic heads and replacing them with oversea ones. That the big difference.

In my case, only my lead and myself survived the trimming. Some joking asked whether my lead and I or the ones that were let go were the lucky/fortunate ones. You see, while others can now go forth with their severance pay and start fresh at another company, my lead and I now have to carry on in a brave new world.

This is the beginning of a series of entries on my experiences working in an outsourced mode. I have been thinking about doing this for some time. And now I have decided to do it. Let's see what comes of it.

To be continued...

Monday, February 4, 2008

Aptana Studio

I had a chance to take an Ajax class recently. It wasn't what I expected, really. What was billed as advanced JavaScript-ing amounted to writing my own $ function, and attaching a function to the array of elements returned. I also got to write my own wrapper around XMLHttpRequest. Not exactly rocket science. Needless to say, I was disappointed.

In any case, I did get some tidbit on closures. Also learned what is "em" in CSS. I also got a chance to use Aptana Studio for the lab exercises. I was pleasantly surprised. It has come a long way.

RadRails got updated, too, since I looked at it last. I will have to check it out, along with Rails 2.0 as well.

Freeciv 2.1.3 Available

The Mac OS X package for Freeciv 2.1.3 is now available. Download it here.