Slideshow transcript
Slide 1: Ruby on Rails Building Web Applications Is Fun Again! Presented by Anthony Eden
Slide 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
Slide 3: The Rails Way DRY (Don’t Repeat Yourself) Convention over configuration Baked in testing Minimal code with maximum effect
Slide 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
Slide 5: Rails on Oracle Key generation assumes sequences for each table with the name ${table_name}_seq Sequence name can be changed using ActiveRecord::Base.set_sequence_name Timezones and sub-second precision not supported More info: http://wiki.rubyonrails.com/rails/pages/Oracle
Slide 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
Slide 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
Slide 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
Slide 9: ActiveRecord Models Object/Relational Mapping Model classes extend from ActiveRecord::Base ActiveRecord::Base 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
Slide 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
Slide 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
Slide 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)
Slide 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
Slide 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
Slide 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
Slide 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
Slide 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 Ladd’s brain




Add a comment on Slide 1
If you have a SlideShare account, login to comment; else you can comment as a guest- Favorites & Groups
Showing 1-50 of 32 (more)