Siltek Software Solutions (I) Pvt. Ltd.
Why does RoR interest us?
Learn “new” concepts and terms.
Look at “new” architecture.
Find out what is good and what is dubious.
May well come across RoR or a Rails-like framework in near
May want to learn an object-oriented language relatively
RoR is easy to install, learn and use. You might want to try
it out for yourself!
Creator of Ruby
Creator of Ruby
Yukihiro Matsumoto aka Matz
Birthday: 24 February 1993
Originated in Japan and Rapidly
Gaining Mindshare in US and Europe.
Brief overview of Ruby
Description of Rails framework
Questions and Answers
Write more understandable code in less lines
Free (Very open license)
What is Ruby?
Dynamic, high level, interpreted, pure object-orientated
“Ruby is designed to make programmers happy”
Yukihiro Matsumoto aka Matz
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
Ruby successfully combines Smalltalk's conceptual elegance, Python's
ease of use and learning and Perl's pragmatism.
Ruby is a metaprogramming language. Metaprogramming is a means
of writing software programs that write or manipulate other programs
thereby making coding faster and more reliable.
Ruby is Truly Object-Oriented
All classes derived from Object including Class (like Java)
but there are no primitives (not like Java at all)
Ruby uses single-inheritance
Mixins give you the power of multiple inheritance
without the headaches
Modules allow addition of behaviors to a class
Reflection is built in along with lots of other highly
dynamic metadata features
Things like ‘=‘ and ‘+’ that you might think are operators
are actually methods (like Smalltalk)
Based on signatures, not class inheritance
A key concept of OOP: methods are actually messages that are
sent to an object instance
Scope Reopening (Kind of like AOP)
Rails applications have a common directory structure
/app - the MVC core
/helpers - provides extra functionality for views
/views/nameofcontroller - templates for controller
/components - will be deprecated
/config - database, route and environment configuration
/db - database schema and migrations
/lib - functions that don’t map to MVC
/script - rails utilities
/test - tests and fixtures
/vendor - 3rd party plugins
Model – View – Controller
• Separate data (model) from user interface (view)
data access and business logic
independent of the view and controller
data presentation and user interaction
read-only access to the model
operating on model and view
Model – Active Record
Object Relational Mapping
Less Database “glue” Code
Logging for Performance Checking
Model : Rules
id for primary key in table
table_id for foreign key in other table
View – Action View
multiple template types
oldest and basic: erb (embedded ruby), similar to e.g. jsp
easy reuse of view elements
file inclusion – layouts, templates, partials
multiple standard "helpers" – common html element
generators (e.g. form elements, paginators)
easy AJAX integration
Controller : ActionController
Method name matches view folder
users_controller.rb works for /views/users/***.rhtml
all view’s methods will sit there
Active Record design pattern
incremental schema management
multiple db adapters
MySQL, PostgreSQL, SQLite, SQL Server, IBM DB2,
Duck Typing in Ruby
Objects are dynamic, and their types are determined at
The type of a Ruby object is much less important than it’s
If a Ruby object walks like a duck and talks like a duck,
then it can be treated as a duck
Convention over Configuration
fixed directory structure
everything has its place – source
files, libs, plugins, database files, documentation etc
file naming conventions
e.g. camel case class name, underscore file name
database naming conventions
table names, primary and foreign keys
standard configuration files
e.g. database connections, environment setting
definitions (development, production, test)
DRY - Don’t Repeat Yourself
e.g. view elements
e.g. no need to declare table field names – can be read
from the database
making each line of code work harder
e.g. mini languages for specific domains
dynamically created methods
Rails Environment Modes
Rails runs in different modes, depending on the parameters
given to the server on startup. Each mode defaults to it’s
own database schema
Development (verbose logging and error messages)
Rails can generate all the basic CRUD operations
for simple models via scaffolding.
Scaffolding is temporary way to get applications
ruby script/generate scaffold_resource
bookmark url:string title:string
Rails uses migrations to version the database.
Rails tries to minimize SQL at every opportunity
Migrations are automatically created whenever you
generate a new model
Migration files are located in db/migrations
The version number is stored in a table called
Running the Migration
Rake is the general purpose build tool for
rails, much like make, or ant. It has many
functions, one of which is to control migrations.
Now the table has been created
Rails has a number of validation helpers that can
be added to the model.
class Bookmark < ActiveRecord::Base
validates_presence_of :url, :title
Action Mailer allows you to send emails from your
application using a mailer model and views. So, in
Rails, emails are used by creating models that
inherit from ActionMailer::Base that live alongside
other models in app/models. Those models have
associated views that appear alongside controller
views in app/views.
Ruby’s Build System
Familiar to Ant users
Your build file is a written in Ruby
Basic build script provided with Rails project
Recommended Rails reading
Simply Rails 2.0
Agile Web Development with Rails
A little bit
Ruby on Rails: Talk (Google Group)
Railscasts (free Ruby on Rails screencasts)
Peep Code (paid Rails-related screencasts)
Phusion Passenger (easy deployment module)
Agile Web Development (plugin central)
Offenbar haben Sie einen Ad-Blocker installiert. Wenn Sie SlideShare auf die Whitelist für Ihren Werbeblocker setzen, helfen Sie unserer Gemeinschaft von Inhaltserstellern.
Sie hassen Werbung?
Wir haben unsere Datenschutzbestimmungen aktualisiert.
Wir haben unsere Datenschutzbestimmungen aktualisiert, um den neuen globalen Regeln zum Thema Datenschutzbestimmungen gerecht zu werden und dir einen Einblick in die begrenzten Möglichkeiten zu geben, wie wir deine Daten nutzen.
Die Einzelheiten findest du unten. Indem du sie akzeptierst, erklärst du dich mit den aktualisierten Datenschutzbestimmungen einverstanden.