Saturday, April 26, 2008

Deployment: Part 1

So we're nearing the stage of our deployment and decided to perform a dry run on J's spare computer. We installed the Ubuntu server on his machine, along with all the stuff we needed (SSH, Ruby, Rails, gems, etc.)

We then decided to go with Ubuntu server + Apache + Mongrel Cluster + Capistrano for an action-packed deployment. We decided on Ubuntu since we have had such a good impression with them and have had experience with troubleshooting on an Ubuntu machine. Apache + Mongrel Cluster seems to be a fast-growing standard, although there are many configurations to choose from. We had been doing research and found that this configuration would be the most painless. As well, this configuration is supposed to handle very well. We used Capistrano to help with our deployment and to make maintenance much easier when deploying on a remote server.

Basically, the whole setup revolved around Capistrano. So... off we went to figure out how to use it. This took us a very long time as we had to troubleshoot some problems.

The first problem that was not even mentioned on the Capistrano site was logging into the remote server with a particular username. In the examples, they simply say to just use:

role :app, my.server.com

However, this will log you into the remote server with the username you have with the local machine. This is not what we wanted, so we ended up having to attach the username in front:

role :app, username@my.server.com

Next, when the server was trying to checkout our repository from SVN, it crapped out. We added this to our deploy.rb to get around this:

default_run_options[:pty] => true

Now, our deploy ran fine, until we got to Mongrel Cluster T.T

Hopefully this will get you out of the rough, unless you're using Mongrel Cluster, which I'll cover in the next post.


W

Friday, April 25, 2008

IE Address Bar

This is really starting to annoy me. In FF, if you type in a URL in the address bar without the http:// and no www, it is smart enough to put them in for you.

However, in IE, without the www, it doesn't know how to prepend the http:// to your address. This gets really annoying when you're constantly trying to go to localhost or a specific IP address for testing.

Sorry for the rant...


W

Thursday, April 17, 2008

Responds_to_parent loc error

If the rjs inside your responds_to_parent block ended up removing the iframe from your html page, the loc variable will no longer be defined.

Besides having an ugly error message on your firebug console, it can actually cause problems for the javascripts on that page as well.

In order the get around this problem, you'll need to do the following patches:

in parent_selector_assertion.rb and responds_to_parent.rb

replace all occurrence of
(3 in parent_selector_assertion, 1 in responds_to_parent)
loc.replace('about:blank');

with
if (window.loc) { loc.replace('about:blank'); }
and that's it!


J

Pluralize

Have you ever had to write some sort of if/else condition to display a sentence involving an object count? Something like 1 person, 2 people, etc.

Well, RoR has a nifty little method called pluralize. All you do is feed it the number and a string, and it will attempt to figure out exactly what you want.

For example:

pluralize(1, 'person') # '1 person'
pluralize(2, 'person') # '2 people'

I thought this was pretty neat and wanted to share with you guys. There are a lot of little methods tucked away in the RoR API, and I encourage you to look through them to help minimize your development time on mundane things like this. Enjoy!


W

Wednesday, April 16, 2008

respond_to + render :partial

RoR has a very quick way to turn your web application into a web service that supports API hooks into your application. It does this using the respond_to method. It's as simple as doing something like:

respond_to do |format|
format.html # automatically calls the corresponding view
format.js #automatically calls the corresponding rjs
format.xml { render :xml => @user.to_xml # or other XML stuff }
end

It's that simple!

Well, there's one odd thing that got me for a little bit. I'm not sure if it's a bug, but when I tried to render a partial in the format.js block, I got an error that it could not find the corresponding template:

respond_to do |format|
format.js { render :partial => 'my_partial' }
end

I found that very odd, but not fixable... I tried adding '.html.erb' to the end of my_partial:

format.js { render :partial => 'my_partial.html.erb' }

And magic! It worked! I'm almost sure this isn't the way RoR is suppose to handle this, but in the meantime, it works! Small hack, but I'm happy :D If any one else runs into this problem, drop a comment, or even better, if you know why or how to solve this, let me know!


W

Tuesday, April 8, 2008

Relatively Absolute Positioning

So I came across a bug in our layout that was driving me nuts. I was trying to lay a div ontop of another div, so I was using relative positioning. Seems reasonable. However, when using relative positioning, it leaves a white gap where the div used to be.

I finally came across this nice little CSS tutorial about positioning and I learned something new. Apparently, you can have an outer div with relative positioning, and have the inner div absolutely positioned inside: a relatively absolute positioned div! Amazing! Since absolute positioning removes the div from the flow completely, no white gap is left behind!

One problem in IE though (as usual), is that anything with relative positioning inside the absolute div is covered up (doesn't show). FF is perfectly fine though (go figure...). I got around this problem by using margins instead.

You may probably know this, but for those that didn't... enjoy!


W

Friday, April 4, 2008

Gedit

So after playing around with Gedit for a while, I'm loving it. It's super fast and there are so many nice plugins to make it very similar to an IDE. There are some things that aren't present, such as refactoring, but that never worked properly in RadRails anyways!

Before, I mentioned that there was no SVN or debugging support. As I continue to develop using Gedit, I have not encountered any problems with this. I'm currently using SVN from the terminal and it's perfectly fine. Lucky I've had experience with using CVS in the terminal ;) Also, I installed a graphical diff program called Meld so that I don't have to look through the classic diff. I haven't had to do too much diffing, so I can't say too much about it.

As for debugging, I realized that for RadRails, I was already using ruby-debug, which runs straight off the terminal! So far, for what little debugging that I have had to do, I found the terminal easier to work with. It requires a bit more typing though (compared to the mouse clicking in RadRails). However, it works... unlike RadRails. The debugger in RadRails was very unpredictable and I could never access the variables without some sort of error popping up. It was so annoying! I'm quite happy with the terminal, so for now, I'm sticking with it.

Apparently, there are new plugins still being developed for Gedit as it gets more popular. Perhaps someone, in time, will come out with an SVN plugin or a debugger plugin. We'll just have to wait and see ;)

In the meantime, I'm super happy with my current setup. There are little things here and there that are bugging me, such as when I hit the home button, it jumps to the beginning of the line, rather than the beginning of the words. I'm hoping there's a configuration that I just haven't found yet.

After playing with it some more, I'll post up the plugins I have installed.


W