Ruby On Rails

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 20

Ruby on Rails

By,
M.KEERTHI TEJA
07AQ1A0532(cse)
CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 1
Ruby on Rails

Ruby on Rails (RoR) is an Open Source web application framework written


in Ruby.

The amazing productivity claims of Rails is the current buzz in the web
development community. If your job is to create or manage web
applications that capture and manipulate relational database from a web-
based user interface, then Ruby on Rails may be the solution you’ve been
looking for to make your web development life easier.

2
CHILKUR BALAJI INSTITUTE OF TECHNOLOGY
What is Ruby?
• Ruby is a pure object-oriented programming language with a super clean
syntax that makes programming elegant and fun.
– In Ruby, everything is an object

• Ruby is an interpreted scripting language, just like Perl, Python and PHP.

• Ruby originated in Japan in 1993 by Yukihiro “matz” Matsumoto, and has


started to become popular worldwide in the past few years as more
English language books and documentation have become available.

• Ruby is a meta programming language. Meta programming is a means of


writing software programs that write or manipulate other programs
thereby making coding faster and more reliable.

3
CHILKUR BALAJI INSTITUTE OF TECHNOLOGY
What is Rails?
• Rails is an open source Ruby framework for developing database-backed
web applications.

• Created by David Heinemeier Hansson.

• All layers in Rails are built to work together so you Don’t Repeat Yourself
and can use a single language from top to bottom.

• Everything in Rails (templates to control flow to business logic) is written


in Ruby
– Except for configuration files - YAML

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 4


Rails Strengths
• Rails embraces test-driven development.
– Unit testing: testing individual pieces of code
– Functional testing: testing how individual pieces of code interact
– Integration testing: testing the whole system

• Three environments: development, testing, and production

• Database Support: Oracle, DB2, SQL Server, MySQL, PostgreSQL, SQLite

• Action Mailer

• Action Web Service

• Prototype for AJAX

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 5


Getting Start with Instant Rails:

• Instant Rails is a software that provides Rails runtime. This software comes
with a bundle contains Ruby, Rails, Apache, and MySQL and all is
preconfigured and ready to run.

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 6


Downloading & Installing Instant Rails:
 Go to  http://rubyforge.org/projects/instantrails  and download latest
version of Instant Rails( ZIP version)

 Unzip the folder in your favourite location.

 Go to that folder where you extracted Instant Rails and


open InstantRails.exe

 When it asks you that the configuration files moved, click OK

 Click unblock to run it from firewall if it prompts.

 Click on   icon and Rails Applications -> Open Ruby Console Window.

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 7


Downloading & Installing Instant Rails:

 Now Ruby console window is opened. Create a new project using


command rails project_name. (ex: rails demo)

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 8


Downloading & Installing Instant
Rails:
 With this command a bunch of files are created in project_folder folder.
To see the files created goto InstantRails->rails_apps->project_folder.

 Now to start rails server locate to project folder what we have created
now by using cd project_name (ex: cd demo)

 Now we are in project folder. From here type ruby script/server.

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 9


Downloading & Installing Instant
Rails:
 This command will run WEB Server.

 Now open browser and try http://localhost:3000. You should see the


welcome screen to make sure that everything is perfect.

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 10


Rails Application Directory Structure
When you are creating a ruby project with help of helper scripts, it
generates the required files and directories required for an application.
The directory structure and naming conventions for every project is same
and here is the some brief introduction of each directory.

app
It contains all the code of that particular project. It also contains three
main folders which reflects the MVC architecture. 

app/controllers
It contains the controller classes. These controllers mainly handles web
requests from users.
app/models
This directory contains the classes which will model and grab the data stored
in application’s database. 

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 11


Rails Application Directory Structure

app/views
The view subdirectory holds the display templates to fill in with data from
our application, convert to HTML, and return to the user’s browser.

app/views/layouts
Holds the template files for layouts to be used with views. This models the
common header/footer method of wrapping views. In your views, define
a layout using the layout :default and create a file named
default.html.erb. Inside default.html.erb,
call <% yield %> to render the view using this layout.

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 12


Rails Application Directory Structure

app/helpers
The helpers directory holds the helper classes and these classes assist the
model, view, and controller classes. 

config
Configuration files for the Rails environment (environment.rb), database
configuration (database.yml) and routing of incoming user requests (routes.rb).

db
Contains the database schema in schema.rb. You can manage the relational
database with scripts you create and place in this directory

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 13


Rails Application Directory Structure

doc
This directory is where your application documentation will be stored. This
documentation can automatically generated using the command rake doc:app

lib
Contains the application libraries. Generally the code which doesn’t belongs to
controllers, models, helpers is stored here and this directory is set in load path.

public
The directory available for the web server. Contains subdirectories for images,
stylesheets,and java scripts. 

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 14


Rails Application Directory Structure

script
Helper scripts for automation and generation. (example launching a web
server)

test
Unit and functional tests along with fixtures. When using the
script/generate scripts, template test files will be generated for you and
placed in this directory.

vendor
External libraries such as third party libraries are stored here.

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 15


The Model-View-Controller Architecture
One of the important feature of Ruby on Rails is it rely on Model-View-
Controller architecture (MVC). The main advantage of MVC is separation
of Business logic from user interface.

Model: Model will stores the information about each table of a database.
It also do some primary validation of data before storing into database.

View: View is generally the interface of your application. Views are often
HTML pages with some embedded ruby code. Views handle the job of
providing the data to web browser.

Controller: Controller mainly handles the incoming requests from the web
browser, interrogating the models for data, and passing that data on to
the views for presentation.

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 16


The Model-View-Controller Architecture

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 17


Summary
• Rail’s two guiding principles:
– Less software (Don’t Repeat Yourself - DRY)
– Convention over Configuration (Write code not configuration files)
• High Productivity and Reduced Development Time
– How long did it take?
– How many lines of code?
>rake stats
– Don’t forget documentation…
>rake appdoc

• Our experience so far.

• Unless you try to do something beyond what you have already mastered, you will
never grow. – Ralph Waldo Emerson

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 18


Rails Resources
• Books
– Agile Web Development with Rails –Thomas/DHH
– Programming Ruby - Thomas
• Web sites
– Ruby Language
http://www.ruby-lang.org/en/
– Ruby on Rails
– http://www.rubyonrails.org/
– Rails API
• Start the Gem Documentation Server
Gem_server http://localhost:8808
– Top Tutorials
http://www.digitalmediaminute.com/article/1816/top-ruby-on-rails-tutorials
– MVC architectural paradigm
http://en.wikipedia.org/wiki/Model-view-controller
http://java.sun.com/blueprints/patterns/MVC-detailed.html

CHILKUR BALAJI INSTITUTE OF TECHNOLOGY 19


Thank you 

20
CHILKUR BALAJI INSTITUTE OF TECHNOLOGY

You might also like