Create Your First Rails Application

ruby_rails_bannerCreating all rails applications in the same way. To create an rails application create a directory and inside the directory run your rails  command

 

 

mkdir rails_application_directory
cd rails_application_directory
rails new my_first_app

output_owekqz

As seen on the above animation a skeleton is created. In this skeleton.

Directory Purpose
app/ This is the core part of the application. This is the place contains models, views, containers
app/assets Which is the place Java Script, CSS and images to be include
 config/  Application Configuration like database configuration, routing…
 db/  Database files
 doc/ documentation files
 lib/  library modules
 log/ log files
 public/  The assets accessible by public ( Error pages … )
 test/  application test files
tmp/  temporary files
 vendor/ 3rd party plugin and Gems
 README.rdoc  A brief description of Application
 Gemfile  Gem requirements
 config.ru  Configuration file for Rake middleware

Bundle Install

When we finish the application creation we are using bundle command to install the application and getting the required Gems to the app. The command bundle install is responsible for the installation it is automatically runs on your creation time.

Note: If you made any changes on Gemfile. You should run the bundle install command to update/install your gems to your application.

 

In Gem you may notice some Gems specified with version number and some are not. Unless you specify the version number Gem getting the latest version of the specified Gems.  You can explicit the version specifying the version number.

gem ‘jquery-rails’

to specify the version as second parameter

gem ‘jquery-rails’, ‘2.0.0’

And also you can specify the particular gem to an particular group environment. Let say we are going to use the sqllite only to the development environment. You specify the Gem as follow.

group :development do
gem ‘sqlite3’, ‘1.3.5’
end

Once you assemble the Gemfile don’t forget to install the Gems inside the application.

bundle install

Rails Server

Until now we have know the two important rails commands rails new and bundle install. Now we are going to see how to run our application. Specially rails comes with a command line with local web server on your development environment.

The following command shows you how to run your rails application on your local machine.

rails server

After running your application, Go to your browser with http://localhost:3000/ You will see the welcome page of rails as below

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s