Ruby on Rails - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Ruby on Rails

Description:

Building Your First App. Create a new Rails app by typing: rails myapp ... Relationships are through primary keys. Supported relationship types: ... – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 18
Provided by: anthony254
Category:
Tags: keys | rails | ruby

less

Transcript and Presenter's Notes

Title: Ruby on Rails


1
Ruby on Rails
  • Building Web Applications Is Fun Again!

2
What is Ruby on Rails?
  • Web application framework written in Ruby
  • Ruby is an Object Oriented scripting language
  • Model-view-controller
  • Database agnostic
  • Open source
  • Lots of nice tools, classes and methods to make
    development easier

3
The Rails Way
  • DRY (Dont Repeat Yourself)
  • Convention over configuration
  • Baked in testing
  • Minimal code with maximum effect

4
Getting Started
  • Installing Ruby, Gem and Rails
  • Install Ruby OCI8 Driver
  • Connect using TNSNAMES.ORA
  • Connect using InstantClient and a URL
  • More information on wiki.rubyonrails.com

5
Rails on Oracle
  • Key generation assumes sequences for each table
    with the name table_name_seq
  • Sequence name can be changed using
    ActiveRecordBase.set_sequence_name
  • Timezones and sub-second precision not supported
  • More info http//wiki.rubyonrails.com/rails/pages
    /Oracle

6
Building Your First App
  • Create a new Rails app by typing rails myapp
  • Edit the config/database.yml
  • Generate a model using script/generate model
    MyModel
  • Creating a model creates a class and a migration

7
ActiveRecord Conventions
  • Naming convention simplifies development and
    encourages good database design
  • Tables are plural, models are singular
  • Example
  • Model LineItem
  • Table line_items
  • Handles non-regular pluralization such as
    Person/people
  • Can be overridden, although this complicates
    things for the developer

8
Database Migrations
  • Database agnostic means of defining schema
  • Lowest-common-denominator approach
  • Ruby code with full access to ActiveRecord
  • Methods for creating, altering and dropping
    tables, columns and indexes
  • Can execute arbitrary SQL with execute method

9
ActiveRecord Models
  • Object/Relational Mapping
  • Model classes extend from ActiveRecordBase
  • ActiveRecordBase provides
  • Database agnostic record creation, finding,
    saving and removal
  • Data validation methods
  • Relationships
  • All in an easy to use package
  • Rails encourages keeping business logic in the
    model where it belongs
  • AR can be used outside of web applications

10
Views
  • Responsible for creating part or all of the page
    displayed in a browser
  • By default uses ERb (Embedded Ruby)
  • Other views include builders for XML documents
    or RJS templates to generate JavaScript for AJAX
    driven views
  • Includes elegant means for including helper
    functions for rendering
  • Supports partials and components

11
Controllers
  • Generate controllers with script/generate
    controller MyController
  • Controllers tie the view to the model through
    actions
  • Controllers also have access to helpers
  • Designed for people-friendly URLs
  • Provides caching, session management, query
    parsing, cookie management, pagination

12
ActiveRecord Relationships
  • Relationships are through primary keys
  • Supported relationship types
  • belongs_to (book belongs to author)
  • has_one (book has one publisher)
  • has_many (book has many pages)
  • has_and_belongs_to_many (book has and belongs to
    many readers)
  • has_many through (book has many contributors
    through contributions)

13
ActiveRecord Validation
  • validates_presence_of
  • validates_uniqueness_of
  • validates_confirmation_of
  • validates_acceptance_of
  • validates_associated
  • validates_each
  • validates_format_of, _length_of
  • validates_exclusion_of, _inclusion_of

14
More ActiveRecord
  • Acts As
  • acts_as_list (position)
  • acts_as_tree (parent_id)
  • Aggregations
  • composed_of
  • Callbacks
  • Full lifecycle
  • Before and after validation, creation, saving,
    destroying
  • Calculations
  • average, count, maximum, minimum, sum

15
Just When You Thought You Had Enough ActiveRecord
  • Callback objects
  • Observers
  • Façade columns
  • Object-level transaction management
  • Magic column names
  • created_on, created_at, updated_on, updated_at
    auto timestamping and dating
  • lock_version and optimistic locking
  • type for single table inheritence
  • xxx_count counter cache

16
Other Stuff
  • ActionMailer for sending mail messages
  • ActionView helpers
  • Form helpers
  • Asset tags
  • Javascript support (yummy AJAX!)
  • Pagination
  • Text helpers
  • ActionWebService
  • Ruby language extensions
  • Breakpoint and debugging

17
Where To Go Next?
  • http//www.rubyonrails.com/
  • http//api.rubyonrails.com/
  • http//wiki.rubyonrails.com/
  • Agile Web Development with Rails
  • http//www.ruby-doc.org/ for Ruby
  • Programming Ruby
  • IRC, Mailing Lists, Seth Ladds brain
Write a Comment
User Comments (0)
About PowerShow.com