Sunday, September 27, 2009

Born out of Boredom

Phew! What a day it was. First of all, it started off by giving my maths exam in college. It was regarding Optimization Techniques, a subject that I currently hate the most. Afterwards, me and my classmates spent more than a hour canvassing our juniors about our upcoming technical event (hope this does'nt goes in vain).
Currently, I am studing javafx, the newer approach for building GUIs in java platform. As mentioned in my earlier posts, i was initially skeptical about this technology. However, just by going through the first chapter of the Apress Pro javafx 1.2 platform, much of my fears have been allayed. Like other pro series, this book does'nt disappoints and covers nearly the entire breadth of the topic and tops off with two examples(rather intriguring, i'd say). I was also worried about the fast pace of this bleeding edge technology, but as release cycles are slow (6months to one year), it is quite an assurance for me. To start off with, I'll be doing GUI programming in java after nearly a three year hiatus because arcane topics like AWT are to be covered in my course this semester, so javafx ought to be refereshing for me. Also, my experience with GUI has never been exactly a satisfying one.
Me, the newbie in javafx, is currently playing around with this yet-another-scripting-language for the jvm and i'd say that its nicely done (expecially the intrgration with Netbeans).
More about this stuff later.

Friday, September 25, 2009

Ebooks for you

I generally get innundated with request from my friends for e-books as you can quickly consult 4-5 books on a given topic as well as save paper.

The files come in two formats: CHM and PDF.

CHM files are basically bundled HTML files and can be extracted to plain HTML.

PDF files are best viewed in Foxit Reader

Surfing today, I came upon this nice website
that hosts a variety of such ebooks.

My request to all subsequent users, please do purchase the original print version, if you find the book useful as it then helps both you and the publisher (and subsequently, the author).

Monday, September 7, 2009

Getting Started With Rails 2

Getting started with Rails 2.0 -A truly Agile Web Development
Rails is a web application framework that enables us to create dynamic, functional and architecturally  well designed websites with ease.

Getting Started:
In Ubuntu Linux, simply type:-
sudo apt-get install rails
Now accept the non standard packages (if there is a warning)

To create a rails application, simply go to the appropriate base folder and type
rails "Application Name"
This would generate all the basic files/folders needed for our application.Note that in Rails 2.0, we need to specify the database of our choice as the default database id sqllite3.To use any other database like MySql, we need to type
rails -D mysql "Application Name"
Make sure that you have the appropriate database application installed at this step. Now look at the database configuration at "Application Directory"/config/database.yml file. In my case, this shows the following data :

For now, lets only concentrate on the development section of the file.
Adapter means the library used to interact with rails. If you do not have the appropriate library, and try to use the database, you would face errors.In the database entry, name an appropriate database name(default or your own liking – whichever you prefer). Then specify username and password. Note that in development environment, we generally leave the password as blank (us lazy programmers :) ). In that case, you still need a space after password: . This is because the space acts as a delimiter (alongwith colon) between the name and value pairs in the file. Lastly, the socket refers to the file that mysql is to be connected from rails on the local computer. This is generated automatically, but you may want to change it if you have more than one distribution of mysql on your machine(In my case, this mysql is installed with lampp distribution).Now we need to create our database. For this, simply type :
This will create the development database.Alternatively, you can even create all the databases

Now before you get bored, lets jump into some serious development work. Keeping the agile manifesto in mind, we need to perform our iteration 0. In rails, this can be done by the scaffold utility. Again, be Very sure of the rails distribution that You are using and the Documentation/Book you are consulting as there is a lot of difference between Rails 1.x and 2.x families. In Rails 2.0 simply type the following command inside your application base directory:
ruby script/generate scaffold Movie title:string about:text url:string
This generates a lot of files (Models, Views and of course, Controllers) for the scaffold. Before commencing with anything, however, keep this in mind that a Scaffold is temporary (just like wooden struts that hold the roof of your house while the roof gets constructed) and should not be used for production code.

Note that the Scaffold name is Movie and it contains name:value pairs of data. You can even have a look into the database and we'll see a table created with name as prural form of our scaffold.Inside the table, rails auto generates a primary key as well as columns having creation and updation status of the records (all this without a single piece of sql/programmer intervention).

After doing this, simply start the server by running the following at command line :
ruby script/server start

This is our initial display of the application. Now play around with the data(perform crud operations to feel the power of this framework).
Note that using scaffold is the exception, not the norm while creating Rails application.

A page view of some newly entered data.
We can even perform validation in the form of models i.e. only the model needs to be refactored in order to perform this task. To do this, simply navigate to the /app/models directory in your rails application. Since in this example, I've created Movie as my model, there would be a movie.rb file in the model directory. It has the following code initially:
class Movie < ActiveRecord::Base


Clearly, the Model has class as Movie and it subclasses the Base class from ActiveRecord module. Inside this, simply insert the folowing piece of code (quite self explaining):
validates_presence_of :title,:about,:url
Now restart/refresh the web browser to observe the change. This time, try performing some validation errors to see the difference.

Thus we can observe the ease of use and the agility of the process involved in the development of a rails application.
Rails is a emerging framework, it is something that is 'bleeding edge' . For up to date information, do look for blogs and discussions on the web. In near future (by end of 2009), Merb framework is going to be integrated with Rails to form Rails 3. So be excited till then.
The following books are my prime sources in learning ruby on rails:

Beginning Ruby On Rails (Wrox)-Steven Holzner
Building Dynamic web 2.0 Websites with Ruby On Rails (Packt Publishing)-A.P. Rajshekhar
Agile Web Development with Rails Second edition (ThePragmatic Bookshelf)-Dave Thomas, David Heinemeier Hansson
Simply Rails 2 (SitePoint)-Patrick Lenz