Get ready to see Rails as you’ve never seen it before. Learn how to extend the framework, change its behavior, and replace whole components to bend it to your will. Eight different test-driven tutorials will help you understand Rails’ inner workings and prepare you to tackle complicated projects with solutions that are well-tested, modular, and easy to maintain.

This second edition of the bestselling Crafting Rails Applications has been updated to Rails 4 and discusses new topics such as streaming, mountable engines, and thread safety.

Buy Now

Select a DRM-free Format:

In Stock
In Stock
In Stock
Buy the eBook and get these DRM-free formats delivered immediately:
  • epub (for iPhone/iPad, Android, eReaders)
  • mobi (for Kindle)
  • PDF
We can automatically send them to your Kindle, and your Dropbox. (You'll need to log in to enable these options.)
 

About this Book

  • 200 pages
  • Published:
  • Release: P1.0 (2013-12-17)
  • ISBN: 978-1-93778-555-0

Rails is one of the most extensible frameworks out there. This pioneering book deep-dives into the Rails plugin APIs and shows you, the intermediate Rails developer, how to use them to write better web applications and make your day-to-day work with Rails more productive.

Rails Core developer José Valim guides you through eight different tutorials, each using test-driven development to build a new Rails plugin or application that solves common problems with these APIs. You’ll learn how the Rails rendering stack works and customize it to read templates from the database while you discover how to mimic Active Record behavior, such as validations, in any other object. You’ll find out how Rails integrates with Rack, the different ways to stream data from your web application, and how to mix Rails engines and Sinatra applications into your Rails apps, so you can choose the most appropriate tool for the job. In addition, you’ll improve your productivity by customizing generators and responders.

This book will help you understand Rails’ inner workings, including generators, template handlers, internationalization, routing, and responders. With the knowledge you’ll gain, you’ll create well-tested, modular, and robust solutions for your next project.

What You Need

This book requires previous experience with Ruby on Rails.

Contents and Extracts

Preface

  • Creating Our Own Renderer excerpt
    • Creating Your First Rails Plugin
    • Writing the Renderer
    • Understanding The Rails Rendering Stack
    • Taking It to the Next Level
    • Wrapping Up
  • Building Models with Active Model
    • Creating Our Model
    • Integration Tests with Capybara
    • Taking It to the Next Level
    • Wrapping Up
  • Retrieving View Templates from Custom Stores
    • Revisiting the Rendering Stack
    • Setting Up a SqlResolver
    • Configuring Our Resolver for Production
    • Serving Templates with Metal
    • Wrapping Up
  • Sending Multipart Emails Using Template Handlers excerpt
    • Playing with the Template Handler API
    • Building a Template Handler with Markdown + ERB
    • Customizing Rails Generators
    • Extending Rails with Railties
    • Wrapping Up
  • Streaming Server Events to Clients Asynchronously excerpt
    • Extending Rails with Engines
    • Live Streaming
    • Filesystem Notifications with Threads
    • Code-Loading Techniques
    • Wrapping up
  • Writing DRY Controllers with Responders
    • Understanding Responders
    • Exploring ActionController::Responder
    • The Flash Responder
    • HTTP Cache Responder
    • More Ways to Customize Generators
    • Wrapping Up
  • Managing Application Events with Mountable Engines
    • Mountable and Isolated Engines
    • Storing Notifications in the Database
    • Rails and Rack
    • Middleware Stacks
    • Streaming with Rack
    • Wrapping Up
  • Translating Applications Using Key-Value Back Ends
    • Revisiting Rails::Application
    • I18n Back Ends and Extensions
    • Rails and Sinatra
    • Taking It to the Next Level with Devise and Capybara
    • Wrapping Up

About the Author

José Valim is the lead developer and co-founder of Plataformatec. He started working with Ruby and Rails in late 2006 and was invited to be part of the Rails Core Team in 2010. He’s also author and maintainer of various other well-known open source projects that led him to receive a Ruby Hero award in recognition for his contributions to the community. Lately, he’s been flying around the globe promoting the concurrency-focused programming language called Elixir.

Comments and Reviews

  • Superb—the most advanced Rails book on the market.

    —Xavier Noria Ruby on Rails consultant
  • In Crafting Rails 4 Applications, José Valim showed me how to make Ruby on Rails dance. I write better code and waste less time fighting the framework because of the tricks he taught me. If you make a living with Ruby on Rails (or would like to), do yourself a favor and read this book.

    —Avdi Grimm Head chef Ruby Tapas
  • This is easily the best continuing-education book for Rails that I have ever read. You learn how things work internally and how you can use that to your advantage when building Rails applications.

    —James Edward Gray Developer Gray Software Productions, Inc.
  • Crafting Rails 4 Applications is the best introduction to Rails internals out there. After reading it I quickly became a Rails contributor.

    —Guillermo Iguaran Lead developer