The Rails 5 Way

Retired

This book is no longer available for sale.

The Rails 5 Way

About the Book

The Rails™ 5 Way is the only comprehensive, authoritative guide to delivering production-quality code with Rails 5.1...

Purchase Now on Amazon

Pioneering Rails expert Obie Fernandez and a team of leading Rails experts illuminate the entire set of Rails APIs, along with the idioms, design approaches, and libraries that make developing applications with Rails so powerful. Drawing on their unsurpassed experience and track record, they address the real challenges development teams face, showing how to use Rails to maximize your productivity.

Using numerous detailed code examples, the author systematically cover Rails key capabilities and subsystems, making this book a reference that you depend on everyday. He presents advanced Rails programming techniques that have been proven effective in day-to-day usage on dozens of production Rails systems and offers important insights into behavior-driven development and production considerations such as scalability. Dive deep into the subtleties of the asset pipeline and other advanced Rails topics such as security and scalability. The Rails 5 Way is your best guide for making Rails do exactly what you want it to do.

Purchase Now on Amazon

About the Author

Obie Fernandez
Obie Fernandez

The "one and only" Obie Fernandez is an avid writer and technology enthusiast, in addition to achieving worldwide success as an electronic music producer and touring DJ. He is Co-founder and Chief Scientist of AI platform Olympia, and also Partner and Chief Consultant at MagmaLabs, a powerhouse Ruby on Rails consultancy.

Obie has been CTO and co-founder of many startups including Mark Zuckerberg's beloved Andela and Trevor Owen's Lean Startup Machine. His published books include the acclaimed business title The Lean Enterprise. He also founded one of the world's best known Ruby on Rails web design and development agencies, Hashrocket and is author of the bible of Rails development, The Rails Way and series editor for Addison-Wesley's Professional Ruby Series.

On the rare occasion when Obie is not busy building products, consulting clients or writing books, you can find him behind the lens of his camera or DJing in the dust at Burning Man.

Follow @obie on Twitter or email him at obiefernandez@gmail.com 

Table of Contents

  • Foreword
  • Foreword (to The Rails 4 Way)
  • Foreword (to The Rails 3 Way)
  • Foreword (to The Rails Way)
  • Acknowledgments
  • About the Author
  • Introduction
    • About This Book
    • David Heinemeier Hansson (aka DHH)
    • Goals
    • Prerequisites
    • Required Technology
    • Licenses, Attributions and Trademark Notice
  • 1. Rails Configuration and Environments
    • 1.1 Bundler
    • 1.2 Startup Scripts
    • 1.3 Default Initializers
    • 1.4 Other Common Initializers
    • 1.5 Spring Application Preloader
    • 1.6 Development Mode
    • 1.7 Test Mode
    • 1.8 Production Mode
    • 1.9 Configuring a Database
    • 1.10 Configuring Application Secrets
    • 1.11 Logging
  • 2. Routing
    • 2.1 The Two Purposes of Routing
    • 2.2 The routes.rb File
    • 2.3 Route Globbing
    • 2.4 Named Routes
    • 2.5 Scoping Routing Rules
    • 2.6 Listing Routes
    • 2.7 Conclusion
  • 3. REST, Resources, and Rails
    • 3.1 REST in a Rather Small Nutshell
    • 3.2 Resources and Representations
    • 3.3 REST in Rails
    • 3.4 Routing and CRUD
    • 3.5 The Standard RESTful Controller Actions
    • 3.6 Singular Resource Routes
    • 3.7 Nested Resources
    • 3.8 Routing Concerns
    • 3.9 RESTful Route Customizations
    • 3.10 Controller-Only Resources
    • 3.11 Different Representations of Resources
    • 3.12 The RESTful Rails Action Set
    • 3.13 Conclusion
  • 4. Working with Controllers
    • 4.1 Rack
    • 4.2 Action Dispatch: Where It All Begins
    • 4.3 Render unto View…
    • 4.4 Additional Layout Options
    • 4.5 Redirecting
    • 4.6 Controller/View Communication
    • 4.7 Action Callbacks
    • 4.8 Streaming
    • 4.9 Variants
    • 4.10 Conclusion
  • 5. Working with Active Record
    • 5.1 The Basics
    • 5.2 Macro-Style Methods
    • 5.3 Defining Attributes
    • 5.4 CRUD: Creating, Reading, Updating, Deleting
    • 5.5 Database Locking
    • 5.6 Querying
    • 5.7 Ignoring Columns
    • 5.8 Connections to Multiple Databases in Different Models
    • 5.9 Using the Database Connection Directly
    • 5.10 Custom SQL Queries
    • 5.11 Other Configuration Options
    • 5.12 Conclusion
  • 6. Active Record Migrations
    • 6.1 Creating Migrations
    • 6.2 Defining Columns
    • 6.3 Transactions
    • 6.4 Data Migration
    • 6.5 Database Schema
    • 6.6 Database Seeding
    • 6.7 Database-Related Tasks
    • 6.8 Conclusion
  • 7. Active Record Associations
    • 7.1 The Association Hierarchy
    • 7.2 One-to-Many Relationships
    • 7.3 Belongs to Associations
    • 7.4 Has Many Associations
    • 7.5 Many-to-Many Relationships
    • 7.6 One-to-One Relationships
    • 7.7 Working with Unsaved Objects and Associations
    • 7.8 Association Extensions
    • 7.9 The CollectionProxy Class
    • 7.10 Conclusion
  • 8. Validations
    • 8.1 Finding Errors
    • 8.2 The Simple Declarative Validations
    • 8.3 Common Validation Options
    • 8.4 Conditional Validation
    • 8.5 Short-form Validation
    • 8.6 Custom Validation Techniques
    • 8.7 Skipping Validations
    • 8.8 Working with the Errors Hash
    • 8.9 Testing Validations with Shoulda
    • 8.10 Conclusion
  • 9. Advanced Active Record
    • 9.1 Scopes
    • 9.2 Callbacks
    • 9.3 Attributes API
    • 9.4 Serialized Attributes
    • 9.5 Enums
    • 9.6 Generating Secure Tokens
    • 9.7 Calculation Methods
    • 9.8 Batch Operations
    • 9.9 Single-Table Inheritance (STI)
    • 9.10 Abstract Base Model Classes
    • 9.11 Polymorphic has_many Relationships
    • 9.12 Foreign-key Constraints
    • 9.13 Modules for Reusing Common Behavior
    • 9.14 Value Objects
    • 9.15 Non-Persisted Models
    • 9.16 Modifying Active Record Classes at Runtime
    • 9.17 PostgreSQL
    • 9.18 Conclusion
  • 10. Action View
    • 10.1 Layouts and Templates
    • 10.2 Partials
    • 10.3 Conclusion
  • 11. All About Helpers
    • 11.1 ActiveModelHelper
    • 11.2 AssetTagHelper
    • 11.3 AssetUrlHelper
    • 11.4 AtomFeedHelper
    • 11.5 CacheHelper
    • 11.6 CaptureHelper
    • 11.7 ControllerHelper
    • 11.8 CsrfHelper
    • 11.9 DateHelper
    • 11.10 DebugHelper
    • 11.11 FormHelper
    • 11.12 FormOptionsHelper
    • 11.13 FormTagHelper
    • 11.14 JavaScriptHelper
    • 11.15 NumberHelper
    • 11.16 OutputSafetyHelper
    • 11.17 RecordTagHelper
    • 11.18 RenderingHelper
    • 11.19 SanitizeHelper
    • 11.20 TagHelper
    • 11.21 TextHelper
    • 11.22 TranslationHelper and the I18n API
    • 11.23 UrlHelper
    • 11.24 Writing Your Own View Helpers
    • 11.25 Wrapping and Generalizing Partials
    • 11.26 Conclusion
  • 12. Haml
    • 12.1 Getting Started
    • 12.2 The Basics
    • 12.3 Doctype
    • 12.4 Comments
    • 12.5 Evaluating Ruby Code
    • 12.6 Helpers
    • 12.7 Filters
    • 12.8 Haml and Content
    • 12.9 Configuration Options
    • 12.10 Conclusion
  • 13. Session Management
    • 13.1 What to Store in the Session
    • 13.2 Storage Mechanisms
    • 13.3 Cookies
    • 13.4 Conclusion
  • 14. Authentication and Authorization
    • 14.1 Warden
    • 14.2 Devise
    • 14.3 has_secure_password
    • 14.4 Pundit
    • 14.5 Conclusion
  • 15. Security
    • 15.1 Password Management
    • 15.2 Log Masking
    • 15.3 SSL (Secure Sockets Layer)
    • 15.4 Model Mass-assignment Attributes Protection
    • 15.5 SQL Injection
    • 15.6 Cross-Site Scripting (XSS)
    • 15.7 XSRF (Cross-Site Request Forgery)
    • 15.8 Session Fixation Attacks
    • 15.9 Keeping Secrets
    • 15.10 Conclusion
  • 16. Action Mailer
    • 16.1 Mailer Models
    • 16.2 Previews
    • 16.3 Receiving Emails
    • 16.4 Testing Email Content
    • 16.5 Sending via API
    • 16.6 Configuration
    • 16.7 Conclusion
  • 17. Caching and Performance
    • 17.1 View Caching
    • 17.2 Data Caching
    • 17.3 Control of Web Caching
    • 17.4 ETags
    • 18. Conclusion
  • 19. Background Processing
    • 19.1 Active Job
    • 19.2 Queueing Backends
    • 19.3 Rails Runner
    • 19.4 Conclusion
  • 20. Asset Pipeline
    • 20.1 Introduction to Asset Management
    • 20.2 Organization. Where Does Everything Go?
    • 20.3 Manifest Files
    • 20.4 Custom Format Handlers
    • 20.5 Post-Processing
    • 20.6 Helpers
    • 20.7 Fingerprinting
    • 20.8 Serving the Files
    • 20.9 Rake Tasks
    • 20.10 Webpack
    • 20.11 Conclusion
  • 21. Ajax on Rails
    • 21.1 Unobtrusive JavaScript
    • 21.2 Ajax and JSON
    • 21.3 Ajax and HTML
    • 21.4 JSONP Requests
    • 21.5 Conclusion
  • 22. Turbolinks
    • 22.1 Turbolinks Usage
    • 22.2 Building Your Turbolinks Application
    • 22.3 Understanding Turbolinks Caching
    • 22.4 Making Transformations Idempotent
    • 22.5 Responding to Page Updates
    • 22.6 Persisting Elements Across Page Loads
    • 22.7 Advanced Turbolinks
    • 22.8 Turbolinks API Reference
    • 22.9 Turbolinks Events
    • 22.10 Conclusion
  • 23. Action Cable
    • 23.1 Web Sockets
    • 23.2 Publish-Subscribe Pattern
    • 23.3 Connections
    • 23.4 Channels
    • 23.5 Subscriptions
    • 23.6 Streams
    • 23.7 Subscriptions Revisited (Browser-Side)
    • 23.8 Rebroadcasting
    • 23.9 Channel Actions
    • 23.10 Configuration
    • 23.11 Running Standalone Cable Servers
    • 23.12 Generator
    • 23.13 Conclusion
  • 24. RSpec
    • 24.1 Introduction
    • 24.2 Behavior-Driven Development
    • 24.3 Basic Syntax and API
    • 24.4 Custom Expectation Matchers
    • 24.5 Helper Methods
    • 24.6 Shared Behaviors
    • 24.7 Shared Context
    • 24.8 Mocks and Stubs
    • 24.9 Running Specs
    • 24.10 Factory Girl
    • 24.11 RSpec and Rails
    • 24.12 Feature Specs with Capybara
    • 24.13 Working with Files in Your Specs
    • 24.14 RSpec Tools
    • 24.15 Conclusion
  • Active Model API Reference
    • AttributeAssignment
    • AttributeMethods
    • Callbacks
    • Conversion
    • Dirty
    • Errors
    • ForbiddenAttributesError
    • Lint::Tests
    • MissingAttributeError
    • Model
    • Name
    • Naming
    • SecurePassword
    • Serialization
    • Serializers::JSON
    • Translation
    • Type
    • ValidationError
    • Validations
    • Validator
  • Active Support API Reference
    • Array
    • Autoload
    • BacktraceCleaner
    • Benchmark
    • Benchmarkable
    • BigDecimal
    • Cache::FileStore
    • Cache::MemCacheStore
    • Cache::MemoryStore
    • Cache::NullStore
    • Cache::Store
    • CachingKeyGenerator
    • Callbacks
    • Class
    • Concern
    • Configurable
    • Date
    • DateAndTime
    • DateTime
    • Dependencies
    • DescendantsTracker
    • Digest::UUID
    • Duration
    • Enumerable
    • ERB::Util
    • EventedFileUpdateChecker
    • FalseClass
    • File
    • FileUpdateChecker
    • Gzip
    • Hash
    • HashWithIndifferentAccess
    • Inflector
    • Inflector::Inflections
    • Integer
    • JSON
    • Kernel
    • KeyGenerator
    • LazyLoadHooks
    • Locale
    • LogSubscriber
    • Logger
    • MessageEncryptor
    • MessageVerifier
    • Module
    • Module::Concerning
    • Multibyte::Chars
    • Multibyte::Unicode
    • NameError
    • NilClass
    • Notifications
    • NumberHelper
    • Numeric
    • Object
    • OrderedOptions
    • ProxyObject
    • Railtie
    • Range
    • Regexp
    • Rescuable
    • SecureRandom
    • SecurityUtils
    • String
    • StringInquirer
    • Subscriber
    • TaggedLogging
    • TestCase
    • Testing::Assertions
    • Thread
    • Time
    • TimeWithZone
    • TimeZone
    • TrueClass
    • XmlMini
  • Rails API
    • Rails API Mode
    • JSON
  • Notes

Other books by this author

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub