Ajax on Rails

Book description

Learn to build dynamic, interactive web applications using the two most important approaches to web development today: Ajax and the phenomenally efficient Ruby on Rails platform. This book teaches intermediate to advanced web developers how to use both Ajax and Rails to quickly build high-performance, scalable applications without being overwhelmed with thousands of lines of JavaScript code. More than just recipes, you also get a thorough, low-level understanding of what's happening under the hood.

  • Ajax on Rails includes three fully worked out Rails/Ajax applications, and quick reference sections for Prototype and script.aculo.us.
  • Testing lessons show you how to eliminate cross-browser JavaScript errors and DOM debugging nightmares using a combination of Firebug, and Venkman.
  • Advanced material explains the most current design practices for Ajax usability. You'll learn to avoid user experience mistakes with proven design patterns.
Beyond the how-to, Ajax on Rails helps you consider when Ajax is (and isn't) appropriate, and the trade-offs associated with it. For those new to Rails, this book provides a quick introduction, the big picture, a walk through the installation process, and some tips on getting started. If you've already started working with Rails and seek to deepen your skill set, you'll find dozens of examples drawn from real-world projects, exhaustive reference for every relevant feature, and expert advice on how to "Ajaxify" your applications.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Assumptions This Book Makes
    2. Contents of This Book
    3. Conventions Used in This Book
    4. Using Code Examples
    5. We’d Like to Hear from You
    6. Safari® Enabled
    7. Acknowledgments
  3. 1. Introduction
    1. Who This Book Is For
    2. What Ajax Is
      1. The Traditional Model
      2. The Ajax Model
      3. It’s Actually Pretty Easy
      4. The Eras of Web Development
      5. History of Ajax
      6. Ajax: Neither Asynchronous nor XML. Discuss.
    3. What Rails Is
      1. Rails Mantras
    4. ‘You Got Your Ajax in My Rails!’
    5. Getting Up to Speed
      1. Starting Ruby
      2. Getting on the Rails
      3. Other Things You’ll Want
      4. Hello, Rails
      5. Rails Writ Large
    6. Summary
  4. 2. Getting Our Feet Wet
    1. The Old-Fashioned Way
      1. Starting a Project
    2. JavaScript Libraries and Prototype
    3. Bringing Rails into the Picture
      1. ERb Basics
      2. Layouts
      3. Partials
      4. Helpers
      5. Back to Ajax
    4. Summary
  5. 3. Introducing Prototype
    1. Setting the Stage
    2. Ajax Links
      1. Callbacks
      2. Other Options
        1. Linking to an arbitrary function
    3. Forms
      1. Form Tag Helpers
      2. Form Helpers
        1. Using form_for
    4. Ajax Forms
    5. Buttons
      1. Buttons for Arbitrary Functions
      2. Custom Helpers
    6. Form Observers
      1. Observing an Entire Form
    7. Summary
  6. 4. Introducing script.aculo.us
    1. Visual Effects
      1. Toggling
      2. Options
      3. Queues
      4. Callbacks
      5. Transitions
      6. Visual Effect Helper
    2. Drag and Drop
      1. Draggables
        1. Draggable options
      2. Droppables
        1. Droppable options
        2. Droppables with Ajax
      3. Sortables
        1. Ajax-enabled sortables
    3. Summary
  7. 5. RJS
    1. Instructions Instead of Data
    2. Putting the R in RJS
      1. Diving In
      2. Rendering JavaScript Without RJS
      3. RJS: Generating JavaScript with Ruby
        1. Using .rjs files
        2. Testing and debugging RJS
      4. Element Proxies
        1. Custom methods with element proxies
        2. Updating content with element proxies
          1. replace_html and replace
          2. reload
      5. Collection Proxies
        1. each
        2. invoke
        3. pluck
        4. collect/map
        5. detect/find
        6. select/find_all
        7. reject
        8. partition
        9. min and max
        10. all and any
        11. inject
        12. zip
        13. sort_by
      6. JavaScriptGenerator Methods
        1. Manipulating DOM elements
        2. Inserting content
        3. Redirecting
        4. Delaying execution
        5. Creating drag-and-drop elements
        6. Generating arbitrary JavaScript
        7. Class proxies
      7. RJS Helpers
      8. RJS Without Ajax
    3. A Real-World Example
      1. The Old Way
      2. The RJS Way
    4. Summary
  8. 6. Ajax Usability
    1. Principles of Usability
      1. Personal Assistant: Defending Attention
      2. Tour Guide: Manage Expectations
        1. User models and program models
        2. Example: Windows versus Mac program models
        3. Set accurate expectations
      3. Mentor: Design Not Just for Usability, but Learnability
        1. Teach with affordances
      4. Trainer: Provide Immediate Feedback
        1. Direct manipulation
        2. Work with the mind
        3. Use color appropriately
    2. The Context of the Web
      1. HTTP
      2. The Page
    3. Usability on the Web
      1. Know When to Use Ajax—and When Not To
        1. Don’t break the back button
        2. Don’t use Ajax for navigation
      2. Keep Page Elements Consistent
      3. Key Commands
      4. Increasing Responsiveness with Ajax (‘It’s Too Slow!’)
      5. Consequences of Increased Responsiveness (‘It’s Too Fast!’)
      6. Blank Slates, Coach Content, and Help Nuggets
        1. Blank slates
        2. Coach content
        3. Help nuggets
    4. Cross-Platform Development
      1. Realities of Platforms
        1. What makes a platform
        2. It isn’t all bad
        3. Dealing with platform differences
      2. The Rails Way
        1. Know your audience
      3. Graceful Degradation and Progressive Enhancement
    5. Summary
  9. 7. Testing and Debugging
    1. Debugging
      1. Understanding Rails Exceptions
      2. Using the Development Log
      3. Interactive Consoles
        1. Using Irb
        2. Using the Rails console with ActiveRecord
        3. Using the Rails console with ActionPack
        4. Rails breakpoints
      4. Inspectors
        1. Using the debug helper
        2. RJS debugging mode
        3. Routing Navigator
        4. FireBug
    2. Testing
      1. Functional Tests
      2. Testing RJS
      3. Testing HTML Validity
      4. Integration Tests
      5. JavaScript Unit Testing
    3. Summary
  10. 8. Security
    1. Healthy Skepticism: Don’t Trust User Input
      1. Using Scoped Queries
      2. Record IDs in URLs
      3. Mass Assignment
      4. Form Validation
      5. SQL Injection
      6. Session Fixation
      7. Cross-Site Scripting
    2. Hashing Passwords
    3. Silencing Logs
    4. The Same-Origin Policy
      1. Creating an Ajax Proxy
      2. Bypassing XMLHttpRequest for Cross-Domain Requests
    5. The Use and Abuse of HTTP Methods
    6. Encryption and Secure Certificates
      1. Ajax over SSL
    7. The Rails Security Mailing List
    8. Summary
  11. 9. Performance
    1. Development and Production Environments
    2. Session Stores
      1. ActiveRecordStore
      2. SQLSessionStore
      3. memcached
      4. Turning Sessions Off
    3. Output Caching
      1. Page Caching
      2. Action Caching
      3. Fragment Caching
      4. Expiring Output Caches
    4. Asset Packaging
    5. Dealing with Long-Running Tasks
    6. Summary
  12. 10. Prototype Reference
    1. Ajax Support
      1. Base Objects
      2. Ajax Requests
        1. Ajax.Request options
        2. Examples
      3. Ajax Updaters
        1. Ajax.Updater options
        2. Examples
      4. Periodical Ajax Updaters
        1. Ajax.PeriodicalUpdater options
        2. Example
      5. Global Responders
        1. Example
    2. DOM Manipulation
      1. $()
      2. $F()
      3. Selectors
        1. Examples
        2. document.getElementsByClassName(className [, parentElement])
      4. Element Methods
      5. class Element.ClassNames
      6. Inserting Content
        1. class Insertion.Before
        2. class Insertion.Top
        3. class Insertion.Bottom
        4. class Insertion.After
        5. Examples
      7. Element Positioning
      8. Form Observers
    3. Core Extensions
      1. Array Extensions
      2. Hashes
      3. Ranges
        1. Example
      4. Enumerable
      5. String Extensions
        1. String Templates
      6. Number Extensions
      7. Events
      8. Function Extensions
        1. Example
      9. Object Extensions
      10. Classes
      11. PeriodicalExecuter
        1. Example
      12. Try.these()
      13. Prototype
  13. 11. script.aculo.us Reference
    1. Visual Effects
      1. Core Effects
      2. Combination Effects
      3. Effect Options
      4. Effect Instance Methods and Properties
      5. Effect Transitions
      6. Effect Callbacks
      7. Effect Queues
      8. Static Effect Methods
    2. Drag and Drop
      1. class Draggable
        1. Examples
        2. Instance methods and properties
      2. Draggables
      3. Droppable Elements
      4. Sortable Elements
    3. Controls
      1. Auto-Completion
        1. Standard options
        2. Local auto-completing
        3. Example
        4. Ajax auto-completion
        5. Example
      2. In-Place Editors
        1. Options
        2. Examples
        3. Instance methods
      3. Sliders
        1. Examples
        2. Instance methods
    4. Element Extensions
    5. DOM Builder
    6. JavaScript Unit Testing
      1. Assertions
    7. Utility Methods
  14. 12. Review Quiz
  15. 13. Photo Gallery
  16. 14. Intranet Workgroup Collaboration
  17. Index
  18. About the Author
  19. Colophon
  20. Copyright

Product information

  • Title: Ajax on Rails
  • Author(s): Scott Raymond
  • Release date: January 2007
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596527440