Upgrading Rails 2.x to Rails 3

I gathered a small collection of sites on how to upgrade from Rails 2.x to Rails 3 for my last job. But we never got around to using it. But instead of throwing away the bookmarks, I thought it might be a good idea to save them somewhere more “permanent”.

One method I keep hearing from others who have done it is to make sure you have decent test coverage for your app. And then upgrade one baby steps at a time: First upgrade to the next immediate major version of Rails, and then the one after that… etc. For example, Rails 2.3.x => 3.0, and then 3.0 => 3.1, and then 3.1 => 3.2… etc. And along the way, fix your code and make sure all the tests pass.

Happy coding.

Postgresql Install Errors on OSX

Update 09/17/2014: I’ve pretty much deprecated use of MacPorts and gone exclusively to Homebrew since this post. And I haven’t run into this problem since this post.

Update 12/28/2012: There’s an easier way to run PostgreSQL! Mattt Thompson has written Postgres app for Mac OSX that allows the database to run completely self-contained! Hassle-free! Last week I was trying out Sinatra and Padrino with PostgreSQL. But for the life of me, I couldn’t get PostgreSQL to run. At first I thought it was an issue with using MacPorts again. But after some googling, it seems like others who used Homebrew also had similar issues.

1
2
3
could not connect to database postgres: could not connect to server: Permission denied
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

There are a couple of ways to deal with this. One of them is to include the PostgreSQL path on OSX’s commandline lookup chain. In your .bash_profile (or .profile for others) file, you could add the path to the PostgreSQL binaries:

 export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/opt/local/lib/postgresql91/bin:$PATH

Make sure the version number on PostgreSQL matches the version you are running.

References
* Installation of Postgresql on MacOS X using Macports
* Installing PostgreSQL 9.0 on Mac OS X 10.6.8 via MacPorts

Segmentation Fault with Rails 3.2.6 on OSX

I was trying to create a new project with Rails 3.2.x. But every time as it runs bundle install, I get the following error:

1
2
3
4
5
6
/Users/home_dir/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
.
.
.
other crap

I tried gem uninstall and reinstalling Rails to no avail. It turns out that Ruby needs to find openssl but couldn’t find it at its preferred location. MacPorts handled all my 3rd party binary needs. But in this case, I wanted to use RVM to handle those packages for dependency reasons.

1
2
3
rvm pkg install iconv
rvm pkg install openssl
rvm reinstall 1.9.3 --with-openssl-dir=~/.rvm/usr --with-iconv-dir=~/.rvm/usr

And that solved the issue for me.

Update 02/22/2013: The lastest version of rvm 1.18.10 apparently will do all kinds of nice things in the background for you to solve the issue as well.

References:

Ruby on Rails Install with “Bad Interpreter” Errors

Today I decided to finally upgrade my Ruby on Rails setup at home. But upon running the rails -v command, I ran into this error:

bash: /opt/local/bin/rails: /opt/local/bin/ruby: bad interpreter: No such file or directory

Turns out for some reason there’s another (non-working) copy of rails in my /opt/local/bin/ directory. To fix the problem, I simply had to remove it (along with rake and other related executables out of there).

On a related note, I also tried upgrading rvm. But while trying to upgrade Ruby to the latest 1.9.3 with it using the rvm install 1.9.3, I kept getting this error:

curl: (7) couldn't connect to host

Finally, what worked was this:

curl -L get.rvm.io | bash -s stable --ruby

And to bind that to rails, similarly, do this:

curl -L get.rvm.io | bash -s stable --rails

That’s it.

Happy hacking.

References:
* Installing RVM
* RVM Repo

Quick Way to Generate Sprites with Corresponding CSS

Discovered Spritemapper over the weekend. You simply point to it a css file and let it lose. Spritemapper does the rest. It combines all the images being used in the css into one big image sprite, writes out an updated css with all the corresponding coordinates to the images, and voilà…

SVN Mania

Versions app

I’ve been meaning to set up Subversion for source control on my various projects. After having worked in an environment with tight source controls for almost half of a year, I’ve gotten used to the convenience and peace of mind of having a source control in place. So today I took the plunge and got svn to work with a SVN client, Versions, along with my favorite lightweight code editor Coda, on my MacBook Pro.

Life is good.

Full Time Employment Again (Almost)

After almost four years of freelancing and eating Bryan’s food scraps, I finally caved in and signed a short-term contract with a local startup as a Flash developer. Since the company is in this super stealth mode, I don’t want to reveal too much about what it is. But I sure look forward to learning some enterprise-level skills after having worked almost entirely independently for a few years.

Actionscript has come a long way with v3.0. But I was surprised how fast I picked it up with my first Flash project a while back considering how much I hated Flash. It’s going to be interesting to see how I will be using it in an almost entirely Object Oriented environment using Model, View, Controller concepts — both of these things I actually wrote on my white board earlier this year as my new year resolutions for 2008…

I will probably hop on the “full time” train once I have checked out the potential of the project. I am definitely not going to repeat the same mistakes when I was a full time employee last.

Ah, life.

Installing Multiple Firefox Version on Windows XP and Mac OSX

As a web developer, one of the worst nightmares has to be dealing with all the different browsers under the sun (not to mention the various versions).

I wrote about installing different versions of Internet Explorer on Windows XP for testing purposes (simply because each version is so drastically bad in its own unique way that you need to test each one of them separately). I had decided to take that one step further with Firefox today.

Thank goodness for oldapps.com, I was able to get hold of Firefox 1.0 and 1.5 to play with in XP.

Installing on Windows XP (not for the faint of heat, or you can try the standalone versions of Firefox without worrying about going through the troubles.):

1. Download and install an older version of Firefox. When you run the installer, make sure you choose

1
custom

installation and install this version in a different directory. For example:

1
Mozilla Firefox 1.0

(in keeping with the default naming convention). Continue installation as prompted. DO NOT RUN Firefox when it’s done.
2. Open Windows Command Prompt and type the following and press

1
Enter

:

1
set MOZ_NO_REMOTE = 1

3. In the same Command Prompt, type

1
cd

and find your way to the version of Firefox you just installed. Using the folder naming convention above, it’s probably something like this:

1
cd /"Program Files"/"Mozilla Firefox 1.0"/

4. Once you are in the directory, type the following and hit

1
Enter

:

1
firefox.exe -profilemanager

5. Firefox’s profile manager should now appear. Now create a new profile and name it accordingly (i.e.

1
firefox1.0

). If you want, name the

1
default

profile to the version of Firefox you currently have prior to the installation.
6. Now go to the appropriate Firefox folders and make shortcuts from them and put them where you access them the most (The Taskbar in my case).
7. Right click on the shortcuts and select

1
Properties

to pull up the Properties window. In it, there’s a

1
<strong>Target</strong>

field. At the end of it (after the double quote), append the bolded typeface in the following:

1
2
3
"C:\Program Files\Mozilla Firefox 1.0\firefox.exe" <strong>-p Firefox1.0</strong>

Do this with each version of Firefox shortcuts you have with a matching profile name. And you are done. The only caveat is you can't run multiple versions of Firefox concurrently like you can with the "Multiple IE" install.

Here’s what my VMWare Windows XP Taskbar looks like:
windows xp taskbar

Installing on Mac OSX:

The process is similar to those found on Windows XP. But I couldn’t get them to work as advertised. So I can’t really endorse the methods here. But there are standalone versions out there that made my life easier.

The upside of Mac OSX is, multiple versions of Firefox can be running at the same time!

UPDATE: I did manage to get multiple Firefox versions to work without asking for a profile upon launch every time as described by Jeroen Coumans‘s blog (PDF). But there’s a trick that you should know about!

For the life of me I couldn’t get them to launch without asking for a profile even though I followed the steps exactly. The problem? I had three versions of Firefox in the same directory labeled:
Firefox 3
Firefox 2.0
Firefox 1.5

That’s a NO to the hack described on the site. In order for the script to recognize the paths, the portion of the name following the word “Firefox” can not be repeated. I have tried “Firefox-” followed by the version number, but that didn’t go. And underscore didn’t do it either. But if you simply remove the space making the names looking like:
Firefox3
Firefox2.0
Firefox1.5

Then all is good.

I will probably install a couple of older versions of Opera as well since they are supposedly pretty simple — simply install different versions of Opera in their own folders and be done with!

via [JiveBay] and [Jeroen Coumans]

Rediscovering Simplicity

I’ve been sweating bullets with this project I’ve been working on with Neely — he’s supposed to be demoing it at a major conference in New York with a partner in a couple of weeks. But I am still not quite where I’d like to be in terms of polish and grace.

Neely’s been telling me to just code for the immediate requirements and nothing more. But my philosophy has always been to look ahead just a little more and prepare for what’s to come as “no-brainer” feature requests. Apparently this type of thinking has been hurting my development time on this project…

I rarely read Wil Shipley’s blog entries because they are usually quite long and sometimes very technical. But just out of the blue I decided to read “something” today. And there I came across his coding strategy and philosophy on coding for only what’s necessary and nothing more.

I’ve always understood the idea of “push it out to the market first and fix it later”… But I just never felt right implementing that in good conscience knowing that I am purposely releasing a faulty software only to fix it when complaints flood in. But the way Wil explained it made a lot of sense to me and I think I am going to make what he says in that article my focus from now on — if there ain’t complaints, it ain’t broke. And if there ain’t requests, it ain’t a useful feature.

Live and learn…

Javascript Debugging for IE

In 2007, the year when the word Web 2.0 is taking over the world of Internet and seen as the resurgence of the another wonderful dot-com era, the world’s favorite web browser, Internet Explorer, still does not have a proper Javascript debugger. You’d have to go through hoops just to get one working by alternative means. How can developers working with IE’s framework love its technologies I guess I’ll never understand…

Some people claim MS is all goodies under the hood for developers. Com’on, where are the goodies? I haven’t met a web developer who doesn’t hate IE.

People who continue to use IE by choice are idiots. There. I’ve said it. Idiots. Idiots. Idiots. Start using better browsers from companies who care so that the World Wide Web can be a better place!

Ok. I feel better now… Back to dealing with crappy IE for idiots who prefer it.

Microsoft should change their marketing tag line to: Your Misery. Our Passion.

Ajax and LAMP Coders Wanted — ASAP

Today I got another call from a recruiter about a potential Ajax/LAMP position they are looking to fill. Without me doing any active advertising, this is probably the 5th or 6th contact from recruiting companies looking to fill a similar position in the San Francisco Bay Area.

This reminds me of Jason’s comment on how his other programmer friends told him that any coder in the Bay Area can get a job if he just sticks his resume on a rock and slingshot it in any direction. Just a couple of days ago, VMWare’s recruiter also contacted me about a similar position…

Too bad I can’t be employed on a full time basis.

Apple Javascript Documentation Ignores IE

I was reading through some documentation on Apple’s Developer Connection site when I noticed that Apple completely left out IE when recommending developers to test their Javascript codes on other browsers.

Apple documentation ignoring IE as recommended browser to test Javascript with

Granted there are actually a number of other browsers not listed there, given IE’s lion’s share in the market, I found it amusing that they chose not to mention it at all. Considering Microsoft bailed out Apple at the brink of its demise back in the days, perhaps Apple ought to be a little nicer to Redmond even if they know Microsoft is just making bad copies of whatever Apple makes anyway…