• No results found

Introduction to Ruby on Rails

N/A
N/A
Protected

Academic year: 2021

Share "Introduction to Ruby on Rails"

Copied!
30
0
0

Loading.... (view fulltext now)

Full text

(1)

Agnieszka Figiel

blog.agnessa.eu

Kraków Ruby Users Group

(2)

Ruby on Rails

"Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern."

www.rubyonrails.org - Ruby on Rails official site

2005 David Heinemeier Hansson

opinionated software:"it’s a very pragmatic, very targeted

framework with a strong sense of direction. You might not share its vision, but it undeniably has one."

(3)

Outline

Design Principles MVC architecture Agile Development

Usability and Success Stories Community and Resources

(4)

Design Principles

MVC architecture Agile Development

Usability and Success Stories Community and Resources

(5)

Model - View - Controller

separate data (model) from user interface (view)

I Model

I data access and business logic I independent of the view and controller I View

I data presentation and user interaction I read-only access to the model

I Controller

I handling events

(6)

Database Persistance

I OR mapping

Active Record design pattern

I migrations

incremental schema management

I multiple db adapters

MySQL, PostgreSQL, SQLite, SQL Server, IBM DB2, Informix, Oracle, Firebird/Interbase, LDAP, SybaseASA

(7)

Full Stack Framework

I MVC suite

I built-in webserver

I default db adapter

I integrated logger

I AJAX, web services, email

I test framework

(8)

Convention over Configuration

I fixed directory structure

everything has its place – source files, libs, plugins, database files, documentation etc

I file naming conventions

e.g. camel case class name, underscore file name

I database naming conventions

table names, primary and foreign keys

I standard configuration files

e.g. database connections, environment setting definitions (development, production, test)

(9)

DRY - Don’t Repeat Yourself

I reusing code

e.g. view elements

I reusing data

e.g. no need to declare table field names – can be read from the database

I making each line of code work harder

e.g. mini languages for specific domains, like object-relational mapping

I metaprogramming

(10)

Design Principles

MVC architecture

Agile Development

Usability and Success Stories Community and Resources

(11)

Model - ActiveRecord

I conventions:

I name based OR mapping: mice db table ->Mouse class I primary key: auto-incremented numeric field called "id" I foreign key: "[singular_of_foreign_table_name]_id", e.g.

"cat_id"

I dynamic getters, setters, finders

dynamic means the existance of a field in db is enough to

manipulate it, e.g. dynamic getter like: mouse.name

I abstracted db operations - create, update, destroy, find, ...

possible to use raw sql, but usually unnecessary, e.g.:

Mouse.find(:all, :include => {:mouse_holes}, :conditions => "location = ’shed’",

(12)

Model - ActiveRecord

I support for basic entity relations (1:1, 1:n, n:n) with

dynamic accessors

backyard_mouse_hole.mice #=> Array of Mouse objects

I parametrised queries against SQL injection, e.g. find all

mice whose name is sth entered by the user:

Mouse.find(:all, :conditions => ["name = ?",

mouse_name)

I validators: an object won’t be saved in db unless it passes

all validation rules, e.g. uniqueness of a given field:

validates_uniqueness_of :login

I object life cycle callbacks, e.g.

before_create, before_save

(13)

View - ActionView

I multiple template types

I oldest and basic: erb (embedded ruby), similar to e.g. jsp I remote javascript templates

I xml templates

I easy reuse of view elements

I file inclusion – layouts, templates, partials

I multiple standard "helpers" – common html element generators (e.g. form elements, paginators)

I ridiculously easy AJAX integration – prototype,

(14)

Controller - ActionController

I all actions grouped logically in controller objects (actions

are public methods of the controller class)

I conventions

I name based url – action mapping e.g. url: myhost.com/mice/show/1

action: ’show’ action in MiceController, params: id=1 I name based action - template file mapping

e.g. action ’show’ in MiceController - template file app/views/mice/show.rhtml

I can be organised in an inheritance hierarchy

reduces code duplication and simplifies code

I action callbacks –

before_filter, after_filter, around_filter

I built-in mechanism of url rewrites – routes

(15)

Design Principles MVC architecture

Agile Development

Usability and Success Stories Community and Resources

(16)

Rapid Development

I built-in webserver

I generators – save the fingers

I scaffold – kick-off start

(17)

Debugging

I verbose log output

I breakpoint debugger

(18)

Testing

I test database + fixtures

I unit tests - tests for models

I functional - tests for controllers

I integration - tests for workflow

(19)

Agile Project Heartbeat

I test coverage - rcov

I continuous integration

I iterative db schema control - migrations

(20)

Design Principles MVC architecture Agile Development

Usability and Success Stories

(21)

Platform Independence

I win, lin, mac

I Apache, Lighttpd, mongrel

(22)

IDEs

I textmate

I vim

I RadRails, Eclipse + RDT, Aptana

I plugins for Idea, NetBeans

I SCiTe

(23)

Scaling

I it scales – a must-see slideshow about scaling twitter (600

req/s!): http://www.slideshare.net/Blaine/scaling-twitter I view caching I page caching I action caching I fragment caching I sql caching I memcached

I shared nothing architecture - multiplying application

(24)

Hosting

I http://wiki.rubyonrails.org/rails/pages/RailsWebHosts

I US - a variety of shared hosting offers

I Poland - poor shared hosting options hosted.pl

(25)

Success Stories

several ror powered high traffic sites

I http://twitter.com/ - community site

I http://www.odeo.com/ - music sharing

I http://www.43things.com/, http://www.43places.com/,

http://www.43people.com/

I 37Signals: BaseCamp, BackPack, Ta-Da List, Writeboard,

CampFire

(26)

Design Principles MVC architecture Agile Development

Usability and Success Stories

(27)

Books

I in English:

I ruby: "Programming Ruby 2nd Edition" (the Pickaxe) Dave Thomas, with Chad Fowler and Andy Hunt

I "Agile Web Development with Rails" Dave Thomas and David Heinemeier Hansson

I "Rails Recipes" Chad Fowler

I many, many more: http://www.rubyonrails.org/books

I in Polish:

I "Programowanie w j ˛ezyku Ruby. Wydanie II" Dave Thomas, Chad Fowler, Andy Hunt

I "Rails. Przepisy" Chad Fowler

I "Ruby on Rails. Wprowadzenie" Bruce A. Tate, Curt Hibbs I "Ruby on Rails. ´Cwiczenia" Michał Sobczak

(28)

Links

I main site: http://www.rubyonrails.org

I PL site: http://www.rubyonrails.pl/

I general mailing list:

http://groups.google.com/group/rubyonrails-talk

I wiki: http://wiki.rubyonrails.org/rails

I api: api.rubyonrails.org

I 74 Quality Ruby on Rails Resources and Tutorials:

http://www.softwaredeveloper.com/features/74-ruby-on-rails-resources-tutorials-050207/

(29)

Events

I Rails Conf

I Rails Day

I local communities & meetings

I Ruby on Rails workshops:

http://rubyonrailsworkshops.com/

(30)

pics:

http://www.midcoast.com/ holo/Seth%20in%20Thailand/pages/Rail%20tracks.html, http://mfrost.typepad.com/cute_overload/2007/05/this_site_is_dr.html

References

Related documents

[r]

The output characteristic (Fig. 6-1) for a water-gated PBTTT film is close to ideal, with very little hysteresis and a low threshold between 0V and 0.1V. The responses of PBTTT

In this review, the research carried out using various ion-exchange resin-like adsorbents including modified clays, lignocellulosic biomasses, chitosan and its derivatives, microbial

While in Table 3 we present a pooled specification, to increase the chances for the added variables to exert a significant impact, in unreported regressions we repeat the

university reform claims that strategic manage- ment has been strengthened in the universities, while the role of university per- sonnel has remained weak. Two major strategy

[r]

[r]

[r]