The Rails 4 Way (5 Copy Package)
The Rails 4 Way
About the Book
The beta period for this book is over. Get your own paper and electronic versions at InformIT or Amazon and other traditional booksellers.
In less than ten years, with fanatical support of a veritable army of open source contributors, Ruby on Rails has forcefully taken its place as the dominant king of web frameworks. It has conquered developer mindshare at startups and enterprises alike with its focus of simplicity, convention and clean, maintainable code. The latest version, Rails 4, continues the tradition of enhanced performance, security and developer productivity, with improvements that enable professional developers to focus on what matters most: delivering business value quickly and consistently.
The Rails™ 4 Way is the only comprehensive, authoritative guide to delivering production-quality code with Rails 4.1. Pioneering Rails expert Obie Fernandez and his 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 4 Way is your best guide for making Rails do exactly what you want it to do.
Notable Changes in the new edition
- Discussion of "omakase" versus "prime" Rails stacks (as advocated by DHH vs TRW, et al)
- Ruby 2.0 support in Rails
- Native support for new Postgres Data types and enhancements in ActiveRecord
- ActiveModel::Model "a really small, handy addition to Rails 4.0, which helps us to get classes that act more like ActiveRecord and easily integrate with ActionPack."
- Asset Pipeline and Sprockets
- Russian Doll-caching through key-based expiration with automatic dependency management of nested templates
- Livestreaming for persistent connections
- Comprehensive coverage of security topics (new chapter, including addition Strong Parameters)
- Changes in HTTP handling in Rails: PATCH vs. PUT
- Turbolinks (and significant updates to the Ajax chapter)
- New comprehensive "Essential Gems" appendix highlighting the best add-on libraries that the Rails ecosystem has to offer
Table of Contents
- Foreword
- Foreword (to The Rails 3 Way)
- Foreword (to The Rails Way)
- Acknowledgments
-
About the Authors
- Obie Fernandez
- Kevin Faustino
-
Introduction
- About This Book
- Recommended Reading and Resources
- Goals
- Prerequisites
- Required Technology
-
1 Rails Environments and Configuration
- 1.1 Bundler
- 1.2 Startup and Application Settings
- 1.3 Development Mode
- 1.4 Test Mode
- 1.5 Production Mode
- 1.6 Configuring a Database
- 1.7 Configuring Application Secrets
- 1.8 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 Where Clauses
- 5.7 Connections to Multiple Databases in Different Models
- 5.8 Using the Database Connection Directly
- 5.9 Other Configuration Options
- 5.10 Conclusion
-
6 Active Record Migrations
- 6.1 Creating Migrations
- 6.2 Data Migration
-
6.3
schema.rb
- 6.4 Database Seeding
- 6.5 Database-Related Rake Tasks
- 6.6 Conclusion
-
7 Active Record Associations
- 7.1 The Association Hierarchy
- 7.2 One-to-Many Relationships
-
7.3 The
belongs_to
Association -
7.4 The
has_many
Association - 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 Calculation Methods
- 9.4 Single-Table Inheritance (STI)
- 9.5 Abstract Base Model Classes
- 9.6 Polymorphic has_many Relationships
- 9.7 Enums
- 9.8 Foreign-key Constraints
- 9.9 Modules for Reusing Common Behavior
- 9.10 Modifying Active Record Classes at Runtime
- 9.11 Using Value Objects
- 9.12 Non-Persisted Models
- 9.13 PostgreSQL enhancements
- 9.14 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
AtomFeedHelper
-
11.4
CacheHelper
-
11.5
CaptureHelper
-
11.6
CsrfHelper
-
11.7
DateHelper
-
11.8
DebugHelper
-
11.9
FormHelper
-
11.10
FormOptionsHelper
-
11.11
FormTagHelper
-
11.12
JavaScriptHelper
-
11.13
NumberHelper
-
11.14
OutputSafetyHelper
-
11.15
RecordTagHelper
-
11.16
RenderingHelper
-
11.17
SanitizeHelper
-
11.18
TagHelper
-
11.19
TextHelper
-
11.20
TranslationHelper
and the I18n API -
11.21
UrlHelper
- 11.22 Writing Your Own View Helpers
- 11.23 Wrapping and Generalizing Partials
- 11.24 Conclusion
-
11.1
-
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 Session Options
- 13.3 Storage Mechanisms
- 13.4 Cookies
- 13.5 Conclusion
-
14 Authentication and Authorization
- 14.1 Devise
- 14.2 has_secure_password
- 14.3 Pundit
- 14.4 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 Setup
- 16.2 Mailer Models
- 16.3 Receiving Emails
- 16.4 Server Configuration
- 16.5 Testing Email Content
- 16.6 Previews
- 16.7 Conclusion
-
17 Caching and Performance
- 17.1 View Caching
- 17.2 Data Caching
- 17.3 Control of Web Caching
- 17.4 ETags
- 17.5 Conclusion
-
18 Background Processing
- 18.1 Delayed Job
- 18.2 Sidekiq
- 18.3 Resque
- 18.4 Rails Runner
- 18.5 Conclusion
-
19 Ajax on Rails
- 19.1 Unobtrusive JavaScript
- 19.2 Turbolinks
- 19.3 Ajax and JSON
- 19.4 Ajax and HTML
- 19.5 Ajax and JavaScript
- 19.6 Conclusion
-
20 Asset Pipeline
- 20.1 Asset Pipeline
- 20.2 Wish List
- 20.3 The Big Picture
- 20.4 Organization. Where does everything go?
- 20.5 Manifest files
- 20.6 Custom format handlers
- 20.7 Post-Processing
- 20.8 Helpers
- 20.9 Fingerprinting
- 20.10 Serving the files
- 20.11 Rake Tasks
- 20.12 Conclusion
-
21 RSpec
- 21.1 Introduction
- 21.2 Basic Syntax and API
- 21.3 Matchers
- 21.4 Custom Expectation Matchers
- 21.5 Shared Behaviors
- 21.6 Shared Context
- 21.7 RSpec’s Mocks and Stubs
- 21.8 Running Specs
- 21.9 RSpec Rails Gem
- 21.10 RSpec Tools
- 21.11 Conclusion
-
22 XML
-
22.1 The
to_xml
Method - 22.2 The XML Builder
- 22.3 Parsing XML
- 22.4 Conclusion
-
22.1 The
-
Active Model API Reference
-
AttributeMethods
-
Callbacks
-
Conversion
-
Dirty
-
Errors
-
ForbiddenAttributesError
-
Lint::Tests
-
Model
-
Name
-
Naming
-
SecurePassword
-
Serialization
-
Serializers::JSON
-
Serializers::Xml
-
Translation
-
Validations
-
Validator
-
-
Active Support API Reference
-
Array
-
ActiveSupport::BacktraceCleaner
-
Benchmark
-
ActiveSupport::Benchmarkable
-
BigDecimal
-
ActiveSupport::Cache::Store
-
ActiveSupport::CachingKeyGenerator
-
ActiveSupport::Callbacks
-
Class
-
ActiveSupport::Concern
-
ActiveSupport::Concurrency
-
ActiveSupport::Configurable
-
Date
-
DateTime
-
ActiveSupport::Dependencies
-
ActiveSupport::Deprecation
-
ActiveSupport::DescendantsTracker
-
ActiveSupport::Duration
-
Enumerable
-
ERB::Util
-
FalseClass
-
File
-
Hash
-
ActiveSupport::Gzip
-
ActiveSupport::HashWithIndifferentAccess
-
ActiveSupport::Inflector::Inflections
-
Integer
-
ActiveSupport::JSON
-
Kernel
-
ActiveSupport::KeyGenerator
-
ActiveSupport::Logger
-
ActiveSupport::MessageEncryptor
-
ActiveSupport::MessageVerifier
-
Module
-
ActiveSupport::Multibyte::Chars
-
NilClass
-
ActiveSupport::Notifications
-
Object
-
ActiveSupport::OrderedHash
-
ActiveSupport::OrderedOptions
-
ActiveSupport::PerThreadRegistry
-
ActiveSupport::ProxyObject
-
ActiveSupport::Railtie
-
Range
-
Regexp
-
ActiveSupport::Rescuable
-
String
-
ActiveSupport::StringInquirer
-
Struct
-
ActiveSupport::Subscriber
-
Symbol
-
ActiveSupport::TaggedLogging
-
ActiveSupport::TestCase
-
ActiveSupport::Testing::Assertions
-
Thread
-
Time
-
ActiveSupport::TimeWithZone
-
ActiveSupport::TimeZone
-
TrueClass
-
ActiveSupport::XmlMini
-
-
Rails Essentials
- Environmental Concerns
- Essential Gems
- Ruby Toolbox
- Screencasts
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.
See full terms
Do Well. Do Good.
Authors have earned$11,830,542writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
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
Top Books
Stratospheric
Tom Hombergs, Björn Wilmsmann, and Philip RiecksFrom Zero to Production with Spring Boot and AWS. All you need to know to get a Spring Boot application into production with AWS. No previous AWS knowledge required.
Go to stratospheric.dev for a tour of the contents.
node-opcua by example
Etienne RossignonGet the best out of node-opcua through a set of documented examples by the author himself that will allow you to create stunning OPCUA Servers or Clients.
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Introduction to Data Science
Rafael A IrizarryThe demand for skilled data science practitioners in industry, academia, and government is rapidly growing. This book introduces concepts from probability, statistical inference, linear regression and machine learning and R programming skills. Throughout the book we demonstrate how these can help you tackle real-world data analysis challenges.
Discrete Mathematics for Computer Science
Alexander Shen, Alexander S. Kulikov, Vladimir Podolskii, and Alexander GolovnevThis book supplements the DM for CS Specialization at Coursera and contains many interactive puzzles, autograded quizzes, and code snippets. They are intended to help you to discover important ideas in discrete mathematics on your own. By purchasing the book, you will get all updates of the book free of charge when they are released.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
Functional Event-Driven Architecture
Gabriel VolpeExplore the event-driven architecture (EDA) in a purely functional way. Learn to design and develop distributed systems that scale. Identify common design patterns in such systems.
Take your functional programming skills to the next level by joining me in developing a distributed system powered by Apache Pulsar and Fs2 streams, all in Scala 3!
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Top Bundles
- #1
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #2
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #3
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #6
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #9
Learn Git, Bash, and Terraform the Hard Way
3 Books
Learn Git, Bash and Terraform using the Hard Way method.These technologies are essential tools in the DevOps armoury. These books walk you through their features and subtleties in a simple, gradual way that reinforces learning rather than baffling you with theory. - #10
Static Analysis and Automated Refactoring
2 Books
As PHP developers we are living in the "Age of Static Analysis". We can use a tool like PHPStan to learn about potential bugs before we ship our code to production, and we can enforce our team's programming standards using custom PHPStan rules. Recipes for Decoupling by Matthias Noback teaches you in great detail how to do this, while also...