Questions Ruby on Rails skeptics ask

[UPDATE: My example for the issue of Rails generating too much database traffic was actually incorrect for Rails v1.0. Luckily, v1.1 introduced bottomless eager loading, which addresses it. I’ve revised the example below.]

If you have been following anything related to web development at all, you have at least heard of Ruby On Rails. If you’re like me, it makes you want to take a flying leap into developing with it. For personal projects there’s nothing to hold you back. However, if you decide to recommend using Rails with a team that doesn’t know much about it, you may run into some questions. If you don’t have some ready answers, the idea will most likely be shot down quickly and left in the dust.

I don’t like using ‘id’ as my primary key name.

Rails is written to expect the field ‘id’ as the primary key to any typical table. Therefore, ‘id’ in a users table would refer to a user id just as ‘id’ in a product table would refer to a product id.

The important thing to know in order to combat this issue is to that while ‘id’ is highly recommended as a primary key, it’s definitely not required. Here’s an example of creating a User model in rails, but telling it that the primary id is UserID instead of ‘id’.

class User < ActiveRecord::Base
  set_primary_key "UserID"

In addition, by naming your own primary key, you need to assign it a unique value prior to saving anything new to the database. Rails can’t assume your new field is auto-generating or not, so it leaves it up to you to set.

My legacy data doesn’t use that naming scheme.

While you are free to use any naming scheme you want, Rails is definitely built to work with its preferred naming scheme. The main thing to keep in mind, in addition to dealing with how Rails works with your primary keys, is you may have to add code to inform your objects how they are related to each other via the database. You could also lose out on automated functionality like Rails ability to automatically take care of fields like created_at.

Rails generates too much database server traffic.

Some people are quick to say Rails makes way too many database calls when you have a number of objects related to each other in one-to-many or many-to-many relationships. This is because Rails does not load data into objects until they are referenced.

For example, if you have an Order and LineItem object where an Order can have many LineItems which in turn are linked to Products you could have something similar to the following code.

for order in Order.find(:all)
  puts "Item ordered: #{order.line_item.product_id}
  puts "Description: #{order.line_item.product.description}

In this example, there would be one database call for the main order, then two calls to retrieve the line item information then the product description. Here’s a much better approach.

for order in Order.find(:all, :include => {:line_items => {:product}})
  puts "Item ordered: #{order.line_item.product_id}
  puts "Description: #{order.line_item.product.description}

Very similar code, but in the latter version the :include attribute tells Rails to preload the line items and products, so it loads up everything in one database call rather than multiple ones. You also have the option of using the find_by_sql function to specify your own custom call.

It’s difficult to find hosting

Finding a host isn’t much of an issue if you have your own server, but if you’re looking for a shared host, not every host offers it. The number grows steadily, though. TextDrive is a leader in Ruby on Rails hosting, but you can find a growing number of hosts on the Ruby on Rails website.

What about performance

Another frequest concern about Rails is about it’s performance and ability to scale. While some think it may be good for small and possibly mid-sized projects, it doesn’t have what it takes for large scale applications. A lot of this is just knee-jerk reaction. The great thing about the Rails community is that there is constant work on making things better.

RailsExpress is one website that is focused on Rails performance. In addition to a lot of benchmarks, it also includes a lot of tips for making Rails apps perform better.

TextDrive also has a weblog which has some of their experiences being a host for Rails apps. Optimizing Rails Resource Usage is one and I’m sure they’ll post more.

Just as you’d expect with any framework and language, the better the code you write, the more efficient it will run.

Have other questions?

There’s a number of great places to find more information on how Rails works. A number can be found on the Rails webpage for documentation. The Ruby on Rails API documentation is the most up-to-date resource since it is actually generated from the code itself although it’s more like looking up things in a dictionary.

For a more hands-on, descriptive resource you should really have the book Agile Web Development with Rails. I have to warn you that the first part of the book will get you ready to tear into your first application, but the juiciest information is in the latter part which goes into more details about the underlying Rails framework.

Where NOT to var…

Ajaxian posted an article about using var to declare a variable at the top level of your script. The variable is considered to be part of the window’s scope which both pollutes the window object and sets up situations where the variable isn’t accessible unless you refer to it as part of the window object itself.

The New MSDN Subscriptions

About 5 years ago now, while I was at the start of being a consultant all on my own, I purchased an MSDN Universal subscription. I went with that level because it was the only one that included the database schema integration with Visio, which I was using to architect databases.

For a consultant, the price tag is high, but you definitely get a lot for your money. It made it a lot easier when I bought it from Vio Software which was recommended by a .NET trainer from a class I was in at the time.

This year, Microsoft updated their MSDN subscription offerings. If you had a Univeral subscription, you could choose between their 3 Team Systems: Architects, Developers or Testers.

Looking over the information, I found that what I really wanted was actually in the middle of the Architect and Developer editions. There were features of both I wanted, but I couldn’t choose both.

I had made the decision to go with the Developer version since it seemed better suited to an individual developer. When I went to Vio Software to place my order, I could only find 2-year subscription renewals. A pre-requisite for these was that you had to renew an existing 2-year subscription.

When I asked about the availability, I was told that since Microsoft restructured their plans, they no longer offered what I wanted through third party resellers.

Since this made the Team Systems more expensive for me, I finally decided to downgrade to the Professional version. I felt like I was backed into a corner and forced to choose between way too much or not quite enough, so I chose the lesser of the two, if nothing else, to avoid having my subscription lapse and having to pay the updated, very high prices for a new subscription.

Initial Vonage Experience

My setup package from Vonage was waiting for me when I got home from work today, so I’ve been busy making some phone calls to test things out.

The instructions were very simple. I have an existing Linksys SRX200 wireless router plugged into my cable modem, so all I had to do was plug a cable from the VoIP router to my existing one, plug in a phone and finally power it up. I immediately got a dial tone and searched through the documents provided to see what else I had to do. That seemed to be it.

I called my own cellphone and since I was right there that didn’t make too good of a test so I called my girlfriend. We could barely understand each other due to the constant fading in and out of sound on both sides. It was like an audio rollercoaster catching every few words of the conversation.

After testing a few things and reading the online help, I disabled the firewall on my Linksys SRX200 and it seems to have fixed my issue. I called my mom and the sound was crystal clear. Better than I would have expected.

I would like to re-enable my router’s firewall but a quick search on the internet wasn’t fruitful, so I’ll have to keep looking. I also need to hook up my DirecTV to it, but there seems to be a lot of info available for doing that.

So far, so good. I’m currently happy with my decision.

UPDATE: Setting up DirecTV was as simple as setting up a ,,#019 dial prefix as described here.

I’m switching to Vonage

I hate SBC After moving down to the Dallas area, I decided to use SBC for my phone service. They seemed to offer some competitive plans for local/long distance calls and they had a really good web site. I signed up. I hate them now.

One of the first features I missed from my old Verizon plan when I lived in the Philadelphia area was answer call. Their automated voice mail system. After going through a number of answering machines it’s one feature I liked a lot. It just always worked.

Since I found out my new SBC plan didn’t include their CallNotes™ feature I had it changed around to add it. Doing this meant moving to a wider area plan which forced me to change my phone number. I don’t know why. Being a new resident, and having deliveries being made, I had to call up everyone to update them. Inconvenient, but I had my voice mail.

I had a plan I thought included free long distance calls, too. I was surprised to get a $230+ phone bill the next month which told me otherwise. It wasn’t free, the plan “included” long distance but that doesn’t specifically say it’s free.

Okay. MCI calls and asks me to switch long distance. I switch. Screw SBC.

My next bill comes and I’m getting more irritated now by my local charges totalling up to $70 a month. About 40% of these seems to be all these mysterious taxes and surcharges.

I would call SBC’s support to weed out unnecessary features, but prior experience with that was awful assuming I could even get through to anyone.

So today, I was prepared to call them and decided to check out VoIP as an alternative. I’ve read a lot of things both for and against, but I’m taking the plunge because I’m disgusted with SBC.

So that’s why I’m switching to Vonage and I’ll report my experiences here. Stay tuned if you’re interested.

More Articles

Page 8 of 9 » ‹ First  < 6 7 8 9 >