Saturday, October 2, 2010

LogU - My Blog Application

Rails Framework

        Rails is a web application framework for the Ruby programming language. It is a powerful application which can be used to build web sites quickly and easy to maintain. A framework is a collection of libraries and tools for the development of an application. A good framework provide complete infrastructure to build our application. Rails is a open source, platform independent framework.
    
        Here in rails it has only less codes and using conventions over configuration. It is simple compared to other framework but little difficult to play with all the conventions.

        Rails uses the MVC pattern, which divides the application logic and pass it to three separate entities- Model(data), View(user interface), Controller(all other actions). Changing any of the entity will not affect other entities.
         A user interact with the interface and provide a form submission. The controller receives this input and pass it to the model, model provides the information according to the form and return it to the controller and pass it to the view and it provides the user interface and pass it to the user.
         The three main library that map directly to MVC are 1.Active Record- which handles the database, 2.Action view- which generates the HTML documents and 3.Action Controller that controls the database and application flow.

Installation
        Type in your terminal:

$ sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev
Download ruby and mkdir ~/src && cd ~/src

$wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p376.tar.gz
$tar -zxvf ruby-1.9.1-p376.tar.gz
$cd ruby-1.9.1-p376
$./configure && make && sudo make install

$sudo gem install rails
$sudo gem update --system
$sudo gem update rails
$sudo gem install sqlite3-ruby

Creating the Application

$rails new blog
$bundle install

To run the server go to the my_app folder and
$rails server

With the server running, if you open http://localhost:3000/ in your browser, you see the Rails welcome page.

To create  our project database

$rake db:create
Rake is a build language for ruby. By calling rake db:create we are creating database for development environment only. For creating all the databases needed for the rails application  type,

$rake db:create:all
 This will create databases for testing and production environment.

$rails db:migrate
This will connect our rails application to the database.

No comments:

Post a Comment