Balancing On Rails

February 08, 2008

Rails Way

Finally I got the book from Amazon.com. I think this book is in high demand because it took long time for Amazon.com to ship it. I also ordered the RailsSpace book along with this one. Both of them are with me now. I decided to read the Rails Way first than the RailsSpace book.

I am a slow reader in the sense that I don't have much time for it. Between jobs and family, the only time I get to read the book is in the night before going to bed. So I somehow manage to read couple of pages. You know how difficult it is to read a technical book at the end of the day.

But one thing I can tell you, this book is a must read if you want to develop Rails app. I would strongly suggest this book over the "Agile Web Development with Rails". The main reason is that Agile Web Development book starts off with an application and then in the later part it tries to explain how Rails work. I feel that the book does not explain everything in detail instead it expects you to do trial and error to figure out everything.

In contrast, Rails Way starts with the basic steps on learning Rails. It starts explaining from how the class loader works and the sequence of loading of the class. Then it slowly moves on to Controller etc. I find this very logical steps if you want to learn Rails in depth. I assume by the time you are done with the book, you would get a thorough understanding of the Rails framework and then it would be an easy task to develop application in rails.

So if you are starting out as a Rails newbie, like me,  drop the Agile book, instead buy this one. This is the only one you would need. It also covers Rails 2.0 which is a bonus!

January 14, 2008

Making a div 100% height - A side note

This has nothing to do with Rails. It has everything to do with CSS. If you have any situation where you want a div to span across the vertical height, here is the solution:

   1: html, body {
   2:     height: 100%; /*key point*/
   3: }
   4:  
   5: #longdiv {
   6:     height: 100%;
   7: }

This should work like a charm in all the browsers. If you have your div wrapped with another div, then don't forget to set the height of the wrapper div too!

January 10, 2008

Tried very hard for Aptana/RadRails

Well, I tried. I love Eclipse. I developed a dislike for NetBeans when I tried it couple of years before. After Eclipse 2.x, I had never looked back at NetBeans. With Ruby, the situation came back again where I had to decide between NetBeans and Aptana/RadRails.

There are other IDEs. But they won't come as close as these two. So I tried NetBeans 6.0 and was totally blown away by all the features and everything so neatly implemented. I don't want to go into details as there have been many rave reviews about NetBeans on the net. A little googling would let you see all those reviews. I wish NetBeans had the smooth font looks like Eclipse! That's the only downside of NetBeans.

However, one thing I loved in Eclipse is Mylyn. It always allowed  me to look at my bugs from Bugzilla. As we use Bugzilla at work, so it was very convenient for me to do all the bug tracking from Eclipse itself. NetBeans does not have that feature yet. It has a task list. But it does not have the bug list integration with Bugzilla. After a little search I found that it is under work and is in alpha mode. However, I could not download the alpha version to test it out. But I assume when it comes out, it is going to be a good one.

Thinking that this might give me an opportunity to look at Aptana again, so I headed to Aptana web site. After downloading it and then installing RadRails plug-in (why don't they have an integrated download?), I fired up the IDE. I tried to import my existing Rails project. But seems like it tried to rewrite the whole project directory again. So I had to keep typing "n" to prevent it from overwriting my files. This means the project importing is not implemented in a right way. 

After it pulled the project in, I could see it in the project explorer. Why could not it use Rails icon? It's a minor thing, but in NetBeans, the Rails icon is used. It gives a better look though!

Then I opened up one of rb file. It was a database table file to create the table. I tried to see if the code completion works or not. I typed "add" and then pressed Ctrl+space to see the code completion. Nothing! Nothing showed up. In NetBeans, by typing "a" itself would show you all the related methods. Ignoring that, I typed "add_index(" and then pressed Ctrl+space. The code completion pop-up showed up. But what waste it is!. It didn't show my table name, neither did it show the columns or anything that is related to the method add_index. No code completion help either! It really got me frustrated! So I did one thing. I closed the IDE and went to explorer. Selected the directory and pressed "Delete"! So bye bye Aptana. May be I will look at it after 2 years. But does not look like it's going to be any good in future. I have a feeling unless Eclipse takes over the job of releasing an IDE for Ruby, it won't get done. So until then I am back to NetBeans and love it more now!

Ruby online course Free!

Finally I decided to take that online course. I know I am kind of an academic guy. Even after reading books, I was not still able to evaluate my skill set on Ruby by myself. So I was looking for some exercises on Ruby to work on so that I can feel myself confident on Ruby. And I stumbled upon this web site called www.rubylearning.org. This is a web site run by Satish Talim. He definitely does a huge favor to all of us ruby beginners. He has a free online course on ruby. And it's like taking a course in any online school. It has assignments, it has quizzes. It has forums to discuss with other people. The only thing it has that the other online school does not have is the number of students. In my batch, there are almost 2800 people taking the course! So if you are thinking of jumping into Ruby, please look at the web site and you can take the course! At last, something is free in life!

December 30, 2007

I am still alive!

My last posting was in August'07 and it's almost end of 2007. You must be thinking where did I vanish. One major thing happened is I got busy at my work. Working for a start-up has it's downfall. And it matters more when you are one of the pillar of the start-up. I can't just discard/delay the work so as to learn Ruby. That would make the customers go away. As much as I want to learn Ruby and Rails, the same amount of motivation I have for the start-up I work for. Hence, for past couple of months, I have been pretty busy and now that things are kind of under control (I hope so), I am back to learning Ruby.

At this point I also want to raise a point that many others might have been going through. I am a Java guy. I have been working on Java for more than 8 years. Before that I had worked on ASP and some amount of Perl. Though I have work consistently on JavaScript, my main development platform has been Java. Being in java world for so long, it's natural that the immediate transformation to a scripting language environment is not that so easy. Though Ruby is a OO language, but still there are some mental blocks that need to be overcome. The reason why people could easily move from C/C++ to Java was that Java maintained the similar way of writing programs. We all know Ruby is a high level programming language. However, with every programming language, it's expected to learn the new syntax etc.. While writing code in Perl or ASP or similar scripting language, you know that there is no concept of objects etc. So you just write your code and the execution happens top to bottom. But while imagining Ruby, somehow I was not able to do so. I was always trying to put Ruby with comparison to Java and it was getting very difficult for me to get out of the mental blocks. A simple example would be that in Java just a simple class that outputs  Hello World would be as below:

   1: class HelloWorld {
   2:     public static void main(String[] argv) {
   3:         System.out.pritnln("Hello World!");
   4:     }
   5: }

Now you know that every time you want to write a stand alone class, you have to have a main  method. But in Ruby, you would write as below:

   1: puts "Hello World!"

And that should work. It works because it's a scripting language. If you don't define a class, then it automatically becomes a part of Kernel object and gets executed.

Similar mental blocks are not easy to go away. So for sometime, I had no clue what I would do to get over the mental blocks. Finally, I found the book Rails for Java Developers  from Pragmatic Bookshelf. This book is a must read for every Java developer who wants to jump into Ruby and Rails. It would take your mental blocks away and get you ready to start writing code in Ruby faster. That's what I am doing now. Reading the book from start to end so that I am ready to balance myself on Rails.

On a side note, Ruby 1.9 is released though it's a development version release. Also released is Rails 2.0.1. Rails 2.0.1 does not support Ruby 1.9 as it got released before Ruby 1.9. This might mean that Ruby 2.0 is not far off and as far as the information in blogging world goes, there won't be much difference from Ruby 1.9 to Ruby 2.0 where as the difference between Ruby 1.8 to Ruby 1.9 is huge. I have not tried it to confirm that. So I assume Rails next version would include Ruby 2.0 if the release is not that far apart from Ruby 1.9.

August 01, 2007

Internationalization

I have no idea why I18N is not implemented either in Ruby or in Rails. I know the only argument that applies to it is that Ruby is still not 2.0. So we should not be expecting many advanced features in Ruby.

Granted that, I think we are in 2007, not in 1997. I can understand if Ruby came out in 1997 and didn't have I18N, it was acceptable. Because web applications were not popular that time.

But we are in 2007 and Ruby on Rails is touted as the best framework available for building web based applications. While we are fighting about scalability of Ruby on Rails for a large scale web application, I am surprised that people are not talking about internationalization.

Yes, there are two plug-ins available for I18N. One is Globalize and other is Globalite. While Globalize is the heavy one, but I disliked it because of the feature that it uses database to store the strings. Coming from Java where resources are stored in a text file and parsed while the application is loaded, always seemed a good idea. I don't want to use database because I don't want my application to connect to database for every string that it wants to internationalized.

Globalite is a lighter model, but the documentation is very poor and I never had a clue how and where I would be setting up the locale information. If anybody can point me in the right direction, I would appreciate that.

Given all that, I am surprised that nobody raises any concern about I18N. If anybody has developed a large scale web based application, that person knows that it's really painful to integrate I18N in a later stage because one has to go inside each file to find out where the text strings are and convert them to appropriate API calls. So it's always advised that I18N should be an important consideration at the beginning of the project. The worst is

puts [ "ant" , "bat" , "cat" ].to_sentence #=> "ant, bat, and cat"

Tell me that when I18N is in place, this API would write "and" in appropriate language. Because that is going to be undetectable in many web application!

Removing a controller

Rails does a lot of automation to generate controllers etc. For an example if you are creating a controller, all you need to do is:

ruby script/generate controller some

This would generate a lot of things like

  • creates a director called some under views
  • creates a file called some_controller.rb under app/controllers directory.
  • creates a file called some_controller_test.rb test/functional directory.
  • creates a file called admin_helper.rb under app/helpers directory.

All this is fine. But let's say I created this controller and later I don't want this controller. I want to remove it. How do I remove it? Is there a automation command that would go through and remove the files for me?

Technorati tags: , ,