Sunday, May 29, 2011

Rails Project Deployment To Heroku

1) After trying out the tutorials of creating a simple rails project named 'Cookbook', i have decided to deploy the project to Heroku. Heroku makes deploying rails projects to the web a breeze. So i have decided to stick on to Heroku as of now.
The cookbook tutorials i have tried is from the following link
This tutorials invovles two tables recipes and categories.

2) After doing the basic sanity testing in the development server, go ahead with the following steps for
    heroku deployment

3) Go to the project directory and enter the command
             git add .
     The above command will create a .git directory in your project directory.

4) Ensure that you are on the master branch using the following command
            git status

5) Commit the files using the following command
            git commit -m "Initial Comment"
    Note the fact that the above command records the changes only in your machine and not on any remote repository. 'git push' is the command which will push the changes to a remote repository.

6) Eventhough this step is not mandatory, its a good practice to push your code changes to a remote social code site such as github. Go to github website and create a new repository named 'Cookbook'.

7) Now push the repository to github using the following commands
           >  git remote add origin
           >  git push origin master
    where lps-162 is my github username and Cookbook is the github repository name

8) Now create a heroku app using the following command
               heroku create
    The above command will create an app with a random name such as

9) Now push the application to heroku using the following command
                git push heroku master

10) Now, we need to migrate the databases also to the heroku environment.
      To create the database migrations in heroku, run the following command
                heroku rake db:migrate

11) If we want to push the data from the development machine, then we can run the following command
                heroku db:pu

Rails Development With MySQL On Ubuntu

     Now that i have installed Aptana studio for Rails Development, I started following the tutorials from the following link.

    Ubuntu comes with in built MySql installation. So i could directly start out with MYSQL development on Ubuntu. To check if MySQL is installed in your system or not, open a command terminal and type in mysql. You will get an access denied message if mySQL is installed.
    Now, use the following command to start mysql.
mysql -u root -p
You will be prompted for root password, The password you should enter is 'root' without quotes.
Then you should be logged into the mysql prompt where you can try all mysql commands.

MySQL Configuration In Rails Project:-
1) You have to mention the mysql database details in the database.yml file in <rails-project-name>/config/ directoy. Make sure that the following contents are there in the database.yml file

# SQLite version 3.x
#   gem install sqlite3
  adapter: mysql
  database: cookbook_development
  username: root
  password: root
  timeout: 5000
  socket: '/var/run/mysqld/mysqld.sock'

You might have make corresponding changes for test and production block in the database.yml file.
For more information on this, have a look at the link which i have mentioned above.

Now, we have to create this database in our mysql system. So run the following command
rake db:create 
in the terminal 

Now create the required controllers, models, views etc using the following command
rails generate scaffold recipes title:string instructions:text
where recipes is the model/controller/view i intended to create.

Now run the rake db:migrate command to create the actual tables 'recipes' in the mysql database.
Now, you are ready to view the recipes pages of our website. All code required for viewing the recipes, adding/editing and deleting the recipes are adding auotmatically by the rails scaffold generator.

You should be able to view the recipes in the dev machine in following link

To set the recipes page as the default page of our website, we can edit the config/routes.rb file 
and modify the line root :to =>  "welcome#index" as follows
root :to => "recipes#index"


Saturday, May 28, 2011

Rails Development using Aptana IDE in Ubuntu

    After having some hands on with Rails development using Vim and command line tools, i started looking for any good IDE for Rails development in Ubuntu. I have been used to software development using tools such as Visual Studio, Eclipse. There are a couple of options available for Rails IDE such as Netbeans, Aptana Studio etc. One problem currenlty i noticed with Netbeans is that the latest release Netbeans 7.0 is not supporting Rails. So you have to use the older version of Netbeans. So unless someone from the community will take up the job of Rails support in latest Netbeans, there wont be support for Rails in Netbeans 7.0 or future releases.

   So, I started looking out for other alternatives. Obviously, Eclipse is a reasonable familiar tool to anyone who had done development with Java. So, i thought i could get my hands on with Rails in Eclipse. I started looking for rails plugin for eclipse and landed up in Aptana Studio site. Aptana studio is based on eclipse and it gives a familiar IDE feel if you are familiar with eclipse.

   I initially installed "Classic Eclipse" and then installed the rails plugin from aptana studio, But i faced some issue after i created a rails project. I got the error message in the terminal window as
"This Terminal Emulator is not functional because no 'bash' shell could be found.Please correct the problem and restart the IDE." I couldnt get much information about this error after googling it.

    But I realized that one can download the standalone version of Aptana Studio from their website. Which will just work out of the box. Just unzip the downloaded zip file and open the aptana launcher.
Also, i modify the default theme of the text editors in Aptana using Windows->Preferences->Aptana->Themes. 

Starting Rails Development In Ubuntu

     After my inital look at lot of users' experiences and comments in various websites, i have decided to start the rails development on Ubuntu. I have been using Windows all these while for all kind of development. But Since most of them stick to Ubuntu or Mac Os for Rails development, i have also decided to take the safe route.

     Instead of trying to install Ubuntu in my windows box with dual boot option, i have decided once again to take the easy route i.e installing Ubuntu VMWare image. I downloaded the latest Ubuntu VMWare image from the VMWare website and also downloaded the free VMware player. I am not that much considered about the performance of the Ubuntu OS as of now. So i have decided to stick on to the VMware version of Ubuntu. But i have experienced some latency in accessing browsers and other network related stuffs.
    I was wondering about the reason behind the latency in my Ubuntu VMWare OS. Could it be probably because i didnt install the VMWare tools yet. Might be.
   I am yet to see how well the system is going to behave after installing the VMWare Tools,
I followed the following procedure to install VMWare Tools.

1) Choose "Install VMWare Tools" Option from the menu in the VMWare player.
2) Then open a terminal and go to a directory where you have write permissions.
    Then do a "tar -xzvf <location_of_Vmware_tools_in_virtual_cd_drive>"
3) The above command will untar the vmware tools to the current directory where you are
    running the command from
4) Then run the command with sudo option
5) Now the vmware tools should be installed
6) After installation, you might instructions/commands to restart the networking related programs.
7) Please follow the commands from the instructions as mentioned in the terminal.
8) And you are done.