Ruby On Rails
Ruby On Rails
Ruby on Rails
Submitted To : Prepared By :
Mr. Naveen Hemrajani Prakash Jodha
Presentation Agenda
Agile Development
Rails Strengths – Full-Stack Web
Framework
Rails implements the model-view-controller (MVC) architecture. The
MVC design pattern separates the component parts of an application
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
Database
Support: Oracle, DB2, SQL Server,
MySQL, PostgreSQL, SQLite
Rails Strengths
Rails Libraries
Action Pack
– Action Controller
– Action View
Active Record
Action Webservices
Action Mailer
Active Support
Rails Environment and Installing the
Software
RailsConsole
WEBrick Web server
Generators
Migrations
Rails Architecture
Rails applications are implemented using the
Model-View-Controller (MVC)
Model - ActiveRecord
View - ActionView
Controller - ActionController
Rails Architecture
Rails Application Directory Structure
App> contains the core of the application
/models> Contains the models, which encapsulate
application business logic
/views/layouts> Contains master templates for each
controller
/views/controllername> Contains templates for
controller actions
/helpers> Contains helpers, which you can write to
provide more functionality to templates.
Cont..
Config> contains application configuration, plus
per-environment configurability - contains the
database.yml file which provides details of the
database to be used with the application
Rails web application can run under virtually any web server,
but the most convenient way to develop and test a Rails web
application is to use the built-in WEBrick web server.
This will start your WEBrick web server listening for Web
Requests at port number 3000 at local machine.
development:
adapter: mysql
encoding: utf8
database: library_development
username: root
password: password
host: localhost
Active Records - Models
Each Active Record object has CRUD (Create, Read, Update, and
Delete) methods for database access. This strategy allows simple
designs and straightforward mappings between database tables and
application objects.
Creating Active Record files
To create the Active Record files for our entities for library
application, issue the following command from the top level of the
application directory.
C:\ruby\library\> ruby script/generate model Book
C:\ruby\library\> ruby script/generate model Subject
You're telling the generator to create models called Book, and
Subject to store instances of books and subjects.
Content available in book.rb
class Book < ActiveRecord::Base
end
When you have more than one model in your rails application, you
would need to create connection between those models. You can do
this via associations. Active Record supports three types of
associations:
one-to-one : A one-to-one relationship exists when one item has
exactly one of another item. For example, a person has exactly one
birthday or a dog has exactly one owner.
one-to-many : A one-to-many relationship exists when a single
object can be a member of many other objects. For instance, one
subject can have many books.
many-to-many : A many-to-many relationship exists when the first
object is related to one or more of a second object, and the second
object is related to one or many of the first object.
You indicate these associations by adding declarations to your
models: has_one, has_many, belongs_to, and
has_and_belongs_to_many.
Creating Associations Between Models:
The process for creating a controller is very easy, and it's similar to
the process we've already used for creating a model. We will create
just one controller here:
Scaffolding provides more than cheap demo thrills. Here are some
benefits:
You can quickly get code in front of your users for feedback.
You are motivated by faster success.
You can learn how Rails works by looking at generated code.
You can use the scaffolding as a foundation to jumpstarts your
development.
Create the User Interface
Partials
/_header.rhtml
/_footer.rhtml
Stylesheets
Publis/stylesheets/*.css
Rails Success Story
Basecamp (info as of late April ’05)
Average lines of code for an action in Basecamp is 5
Written in 9 months
Tens of thousands of users
300k dynamic page renders/day
Hosted on two app servers with 15 fastcgi processes
each + one MySQL server
THANK YOU