Monday, July 21, 2008

Ruby On Rails Quickly (hopefully)

When I first started working on Ruby on Rails there were a plethora of tutorials. I found none current; some too lengthy and circuitous , others indirect; in short I had a difficult time with something that was supposed to be "painless".(ruby on rails motto?) Here is my attempt to get "something" satisfying up and running in the fewest steps as possible.

The goal is to display a major strength of ROR : generate a create, update, delete form.
1) First you will need to setup by installing ruby (the language or rather its "interpreter") download ruby interpreter 1.8.6-26( [download page][direct])















2) install ruby








2a)Dont forget to pick a simple directory structure like c:/ruby as follows:

3) You will need to add rails to ruby so go to the directory and type gem install rails (you now have ruby on rails, phew!)

4) You will need a database so download mysql and install

5) You want to view your tables in a user friendly way through a GUI so download mysql gui tools and install (to view your tables)

Now we shall create our application:
6) create your application in your install directory so go to your command line prompt and go to your install directory (c:/ruby/)
7) create your test application "rails test"

8) Since you wish to use your mysql db you may want to setup your database connection by typing "rails test -d mysql"
This creates a "mysql connection" by overwriting the following database.yml file
the above refers to some sqllite db ; but since the majority uses Mysql the command "rails test -d mysql" changes the code to this


Note: don't forget to put the password into the database.yml file please.

9) The "database connection" (file) says that since you are in development you are going to use the "test_development" database. This means you must have "test_development" database in your mysql db.
9a) So please create it so by typing rake db:create
Now check to see if the databases test_development is created by going to mysql admin tool


Now finally comes the part that ruby on rails excels at, rapid development (everything else above was "setup" or the boring stuff called "exposition" whereas now the action begins):
What we will do now is create a create , update delete form with some generic fields. Usually you have to create the tables, create the view and the controller and modify or add the data layer. Loads of tedious mechanics. Not with Ruby and rails.
10) change directory to your application "test" working directory

10b) To see some form in action : Suppose we wanted to create a form where you can enter your name and age. We would like to create a table called users and views which allow us to create, update and delete. So type something like :
ruby script/generate scaffold user name:string age:integer
(the italicized words are keywords in ruby on rails. The red text defines the table you are creating. USE SINGULAR and it will create a pluralised table called users as a table name. The rest of the parameteres like name and age define the columns of this table and next to the columns is their datatype)

This will create everything above the database : the model, view and controller. What remains is the creation of the tables in the database.

11) Now to create the table in the database:
rake db:migrate
12) go to your mysql administrator page and then right click and refresh. You will see the newly created table.

13) Before we test out the form we need to start the server by typing
ruby script/server
You can see that the the appserver is up by checking it with http://localhost:3000


14) view the application by typing:
http://localhost:3000/users
It shows you the list of users which are zero right now.

(note how you have used the table name "users" (plural) to access the table and its forms although you initially specified a singular)
15) create a user by clicking on "New user" and you will see the rudimentary form:

16) After entering the information and pressing "create" you may see the list of users here:






In conclusion this just shows you how to rapidly create the foundations or groundwork for your web forms. There is a lot more to rails which makes it useful as a tool. If you feel that this is too "pre packaged" then don't. Your application is HIGHLY configurable. Rails' strength is that it can get you to a goal in the least number of steps and YET its highly configurable.


Journey to Ruby on Rails

My journey to Ruby on Rails (ROR) was typical of the journeys of all who attempt to deal with non-Microsoft technologies : it involved entire weekends spent just installing; figuring out how to install; figuring out dependencies; figuring out a decent tutorial (that is not obsolete); translating the tutorial to work with your install; if after all that everything works then we will be lucky.

Lucky because the more the steps the higher the likelihood of failure. Microsoft's technology reduces the steps to a goal but still provides access to configuration ; that is something the rest of the development community has not learned/ implemented/ ingrained primarily because we have non technical "forceful" personalities leading the other side.

So I started working on Ruby on Rails around March 22nd or so after my last Winter class at Stanford. I went through Friends of Ed Rails Made Easy (it was not!) the best part of rails was reserved for the concluding chapter! That is typical of folks who are suffering from poverty of goodness : they force you to go through the motions reserving the "good stuff" for the end because they want to "reward the patient" or "inculcate good habits" or "teach discipline".

If we wanted to learn that we would go to a boot camp! Show us what is so great about ROR immediately, right? It takes a great deal of courage and generosity to get to the point and get to it quick and give the reader the meat and potatoes right away. May God help us, I shall attempt to do that in the next post.

Sunday, July 20, 2008

Writing Install Utility for JAMES: Java Apache Mail Enterprise Server

When I first wrote the install utility a few MONTHS ago the reaction was lukewarm to say the least (1). So I have decided to write this blog in the hope that someone will notice and proceed with this path. If my installer is not accepted perhaps someone else's will be and the world will be better off with having an easy to install JAMES installer.
1) Using Setupbuilder I wrote a James Installer project by first creating a new project so :
2) After the usual software driven questionnaire (pick installation directory, pick name etc.) the most common error most people make when writing installers with setupbuilder is this one:


the installer writer usually forgets to pick the directories AND the files icon in the bar. If you will recall from the previous post that to install JAMES you need the Java Activation Framework files and the Javamail API files.

3) the next big step was to check for the existence of the JRE in the registry of windows :



4) Some of the configuration for JAMES can be seen here :
5) You may download the installer executable here[1]

6) Running the installer should look like so:

7) It will ask you to approve the Apache License here :

8) pick destination folder

9) installing
10) double check :
11) that is it! that is how installers should be?

What remains is to start the JAMEs server automatically, to give the option of installing it as a service and to check for any previous installs or editions.

P.S. To install JAMES as a windows service:
C:\Tools\james-2.2.0\bin>wrapper -i ..\conf\wrapper.conf
you should see:
wrapper | James Mail Server 2.1 installed.

To remove James as a windows service:
C:\Tools\james-2.2.0\bin>wrapper -r ..\conf\wrapper.conf
you should see:
wrapper | James Mail Server 2.1 removed.

Note: To get more information about the wrapper command, type: C:\Tools\james-2.2.0\bin>wrapper

Thursday, July 17, 2008

How to Install JAMES :JAVA APACHE MAIL ENTERPRISE SERVER

Previously I exhibited code that interacted with JAMES and created users and sent and received emails. But when I first began I found that installing or setting up JAMES was rather primitive (unzipping files, setting environment variables manually and typing "run.bat"!) This is a tutorial for those who still have to do it the hard way (hopefully this way will become obsolete with the introduction of an executable; in the next post I will go over how I wrote the installer for JAMES):

1) Download the Java Activation Framework (deprecated for javamail and jaf are already part of james-2.3.1 distribution)
2) Download the JavaMail API (deprecated for javamail and jaf are already part of james-2.3.1 distribution)
3) Download JAMES [page][zip]
4) unzip the downloads from steps 1-3 and organize them in a directory so :

4) Download and install a java vm (1.4+) [page]
6) check for installation of JVM in step 4 by typing java -version on command line:
7) (optional) check that JAVA_HOME is set:


double check so :
8) setup the username and pwd for logging into JAMES (to be safe)
8.a) go to config.xml (in our case located in C:\James\james-2.3.1\apps\james\SAR-INF\config.xml)
8.b) Go to line 798 (approx) : And change the default user and password from root / root to maybe difficultusername/ difficulttobreakpwd
9) Now type run.bat from the james-2.3.1\bin directory :


10) That should start JAMES. phew! Compared to the next->next-> installation that most of humanity is used to ... that was difficult, wasn't it?

References:"Quick start" ; this tutorial

How To Import IXF Files into DB2

This was an easy one to do. I volunteered to help some people at the office and they mistakenly thought I was a "DB2 expert" despite my re assuring them that I find the job of "DBA" a sinecure, that I don't see it as a compliment and that even if I did I am not a DB2 expert.

Step 1 : Open Control center

Step 2: Specify the control center view (Advanced maybe)
Step 3: open tables folder from an existing db (into which you are importing the ixf file)
Step 3: open tables from an existing db, right click and import "Create from Import" (select that)

Step 4: The import table window ought to pop up

Step 5: Go to import file and click on the "..." and the import file view ought to pop up

Step 6: The error messages field (see illustration) says : Create an error messages file and point to it or have the error messages field point to some text or log file (I just created a log.txt and pointed to it)

Step 7: Select this created error file
Step 8: You may have to enter the table name

Step 9: When OK button highlights you are ready to import and you do!


Pretty straightforward; everyone was so grateful ;I was immediately hailed and congratulated but I was slightly indignant. Unfortunately IBM makes it rather complicated (unlike in mysql or sqlserver 2000) Instead of figuring this out should not the faculties of men be engaged in defeating disease, hunger, inefficient (antiquated) laws, precepts, superstitions and traditions? should not it be engaged in rolling amongst wildflowers upon verdant hills (preferably with an attractive beloved)? Why so many deserts? Why so many hardened brutes? I bet the coal miners of the industrial era ( even today) think that . Yet do none have the courage to confront this? to edify and liberate the working classes?

How To Reverse Engineer ER Diagram From MySQL in Visio

When you first open visio and go to File ->New->Getting Started-> Software and Database ->Database Model Diagram-> (from File Menu) Database-> Reverse Engineer you dont see any sign of mysql drivers.
Step 1: download the ODBC mysql driver!
Step 1.a: install

Now there are two ways of going about this one is through Visio (easiest).
Step 2 (via visio): Open Visio go to File ->New->Getting Started-> Software and Database ->Database Model Diagram-> (from File Menu) Database-> Reverse Engineer and then select ODBC Generic Driver under installed Visio Driver and click on "New ..." button underneath setup.


Step 3 (via visio): Select "User Data Source" and click on Next and then scroll down to select the "MySql ODBC 5.1/VERSION Driver" at the bottom as in the picture.
Step 4 (via visio): Click on Next and then it will say "When you click finish you will create the datasource you have just configured.The driver may prompt you for more information " click Finish.


Step 5 (via visio): When you click on finish it will prompt you for your database information. This is what my mysql db looks like :

The db name is letter4sure_development and the port is the default 3306 and then you just enter the user name and password so and try to "test" the connection :
As you can see the test connection was successful.
Step 6 (via visio): Now it should show up in your drop down so:

Step 7 (via visio): Now Visio should ask for the password again (and from here you should be able to handle this on your own but for completeness I will elaborate further):

It may give a warning about incompatible drivers (I ignored it).
Step 8 (via visio):
You now select the primary keys, indexes and foreign keys you want imported. Step 9 (via visio): Now you select the tables (if you are using Ruby on Rails as I am do not select "schema info" since that table is used by the rake migrations table, remember!
Step 10 (via visio): Visio will ask if you want to add the shapes check "yes" and click next to see the following confirmation window (almost there):
Step 11 (via visio): View the generated schema and wish the author of this blog "Athar Shiraz Siddiqui" good will and blessings. Hopefully this was helpful for you...

Total Pageviews

Popular Posts