1. Ruby On Rails
Web Application Framework
D. Prabu
Senior Technical Consultant,
Spritle Software PVT LTD,
Chennai.
2. History
• David Heinemeier Hansson extracted
Ruby on Rails from his work
on BaseCamp, a project management
tool by 37signals.
• Hansson first released Rails as
open source in July 2004.
• Rails 4.0 Final version released.
3. WAF
• A web application framework (WAF) is a software
framework that is designed to support the development
of dynamic websites, web applications, web services and web
resources.
• Rails is a web-application framework that includes everything
needed to create database-backed web applications according
to the Model-View-Controller (MVC) pattern.
5. Model (Active Record)
• It is responsible for representing business
data and logic
• It takes how to Write and Read from the
database.
• ORM, is a technique that connects the rich
objects of an application to tables in DB.
6. View (Layout)
• To generate an output representation to the
user.
• It is composed of “templates”, that are
responsible for providing appropriate
representations of your application’s
resource.
• Templates can come in a variety of formats,
but most view templates are HTML with
embedded Ruby code.
7. Controller
• It is responsible for handling incoming
HTTP requests and providing a suitable
response.
• Rails controllers can generate HTML,
XML, JSON, PDFs, and more.
In Rails, the Controller and View layers are
handled together by Action Pack.
8.
9. Rails Strengths
It has grown when it comes to the number of
features allowing developers to achieve more in less time.
• Convention over configuration
Most web development frameworks for .NET or
Java force you to write pages of configuration code.
Rails doesn't need much configuration.
Developers to focus on “what they are doing ”
instead of on “how they are doing it” the approach is
meant to boost their productivity.
• DRY concept
Keep your business logic in one place.
10. Create a new rails application
$ > rails new blog
11. ROR Languages used …
Largest sites running in Ruby on Rails
Twitter
Github
Yammer
Scribd
Groupon
Shopify
Basecamp
12. Blogs
id title tags
1. Benefits Of Ruby RUBY
2. Mobile Frameworks MOBILE
3. Getting Started with Personal Web Pages WEB
4. Responsive Web Design CSS
5. Practicing Ruby RUBY
Question :
Retrieve a hash of the blog title with id = 3
13. Blogs
id title tags
1. Benefits Of Ruby RUBY
2. Mobile Frameworks MOBILE
3. Getting Started with Personal Web Pages WEB
4. Responsive Web Design CSS
5. Practicing Ruby RUBY
Question :
Retrieve a hash of the blog title with id = 3
Answer :
Result = { :title => “Getting Started with Personal Web Pages” , :tags=>” WEB” }
14. result = { :title => “Getting Started with Personal Web Pages” ,
:tags=>” WEB” }
puts result[:title] => “Getting Started with Personal Web Pages”
puts result[:tags] => “WEB”
(or)
puts result.title => “Getting Started with Personal Web Pages”
puts result.tags => “WEB”
HASH
Series of key value pairs
15. id title tags
1. Benefits Of Ruby RUBY
2. Mobile Frameworks MOBILE
3. Getting Started with Personal
Web Pages
WEB
4. Responsive Web Design CSS
5. Practicing Ruby RUBY
Blogs
b = Blog.find(3)Answer :
Question : Retrieve a hash of the blog title with id = 3
puts b[:title] => “Getting Started with Personal Web Pages”
puts b[:tags] => “WEB”
puts b[:id] => 3
Pluralize
18. Read
Blog.find(2) # Returns a single item
Blog.find(3, 4, 5)
Blog.first
# Returns an array
# Returns the first blog
Blog.order(:tags) # All ordered by tags
Blog.last # Returns the last blog
Blog.all
Blog.limit (10)
# Returns all the blogs
# Only 10 blogs
Blog.where(:tags =>“ruby”) # Only blogs by ruby
Blog.where(:tags => “ruby").order(:tags).limit(10)