Foreword to the Rails 7 Edition....11
Preface to the Rails 7 Edition....14
Acknowledgments....16
Introduction....18
Rails Simply Feels Right....19
Rails Is Agile....22
Who This Book Is For....24
How to Read This Book....25
Part I. Getting Started....29
1. Installing Rails....31
Installing on Windows....33
Installing on macOS....38
Installing on Linux....41
Choosing a Rails Version....46
Setting Up Your Development Environment....47
Rails and Databases....52
2. Instant Gratification....56
Creating a New Application....57
Hello, Rails!....61
Linking Pages Together....69
When Things Go Wrong....73
3. The Architecture of Rails Applications....79
Models, Views, and Controllers....80
Rails Model Support....84
Action Pack: The View and Controller....87
4. Introduction to Ruby....91
Ruby Is an Object-Oriented Language....92
Data Types....95
Logic....101
Organizing Structures....105
Marshaling Objects....109
Pulling It All Together....110
Ruby Idioms....112
Part II. Building an Application....116
5. The Depot Application....118
Incremental Development....119
What Depot Does....120
Let’s Code....125
6. Task A: Creating the Application....127
Iteration A1: Creating the Product Maintenance Application....128
Iteration A2: Making Prettier Listings....138
7. Task B: Validation and Unit Testing....149
Iteration B1: Validating!....150
Iteration B2: Unit Testing of Models....155
8. Task C: Catalog Display....171
Iteration C1: Creating the Catalog Listing....172
Iteration C2: Adding a Page Layout....177
Iteration C3: Using a Helper to Format the Price....180
Iteration C4: Functional Testing of Controllers....182
Iteration C5: Caching of Partial Results....186
9. Task D: Cart Creation....192
Iteration D1: Finding a Cart....193
Iteration D2: Connecting Products to Carts....195
Iteration D3: Adding a Button....199
10. Task E: A Smarter Cart....209
Iteration E1: Creating a Smarter Cart....210
Iteration E2: Handling Errors....218
Iteration E3: Finishing the Cart....223
11. Task F: Hotwiring the Storefront....231
Iteration F1: Moving the Cart....233
Iteration F2: Creating a Hotwired Cart....241
Iteration F3: Highlighting Changes....248
Iteration F4: Broadcasting Updates with Action Cable....252
12. Task G: Check Out!....261
Iteration G1: Capturing an Order....262
Iteration G2: Adding Fields Dynamically to a Form....278
Iteration G3: Testing Our JavaScript Functionality....286
13. Task H: Sending Emails and Processing Payments Efficiently....293
Iteration H1: Sending Confirmation Emails....294
Iteration H2: Connecting to a Slow Payment Processor with Active Job....303
14. Task I: Logging In....317
Iteration I1: Adding Users....318
Iteration I2: Authenticating Users....324
Iteration I3: Limiting Access....331
Iteration I4: Adding a Sidebar, More Administration....335
15. Task J: Internationalization....343
Iteration J1: Selecting the Locale....345
Iteration J2: Translating the Storefront....351
Iteration J3: Translating Checkout....360
Iteration J4: Adding a Locale Switcher....369
16. Task K: Receive Emails and Respond with Rich Text....374
Iteration K1: Receiving Support Emails with Action Mailbox....375
Iteration K2: Storing Support Requests from Our Mailbox....383
Iteration K3: Responding with Rich Text....391
17. Task L: Deployment and Production....404
Configuring the Database....407
Managing Secrets....410
Building a Docker Image....412
Getting Up and Running....416
Checking Up on a Deployed Application....418
18. Depot Retrospective....424
Rails Concepts....425
Documenting What We’ve Done....429
Part III. Rails in Depth....431
19. Finding Your Way Around Rails....433
Where Things Go....434
Naming Conventions....444
20. Active Record....451
Defining Your Data....452
Locating and Traversing Records....459
Creating, Reading, Updating, and Deleting (CRUD)....464
Participating in the Monitoring Process....483
Transactions....491
21. Action Dispatch and Action Controller....498
Dispatching Requests to Controllers....500
Processing of Requests....514
Objects and Operations That Span Requests....529
22. Action View....543
Using Templates....544
Generating Forms....547
Processing Forms....551
Uploading Files to Rails Applications....553
Using Helpers....558
Reducing Maintenance with Layouts and Partials....567
23. Migrations....580
Creating and Running Migrations....581
Anatomy of a Migration....585
Managing Tables....591
Advanced Migrations....598
When Migrations Go Bad....600
Schema Manipulation Outside Migrations....602
24. Customizing and Extending Rails....605
Creating a Reusable Web Component....606
Testing with RSpec....608
Creating HTML Templates with Slim....616
Customizing Rails in Other Ways....619
Where to Go from Here....620
Bibliography....624
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single-page applications - at a fraction of the complexity. Rails 7 integrates the Hotwire frameworks of Stimulus and Turbo directly as the new defaults, together with that hot newness of import maps. The result is a toolkit so powerful that it allows a single individual to create modern applications upon which they can build a competitive business. The way it used to be.
Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly - you concentrate on creating the application, and Rails takes care of the details. Rails 7 brings many improvements, and this edition is updated to cover the new features and changes in best practices.
We start with a step-by-step walkthrough of building a real application, and in-depth chapters look at the built-in Rails features. Follow along with an extended tutorial as you write a web-based store application. Eliminate tedious configuration and housekeeping, seamlessly incorporate JavaScript, send and receive emails, manage background jobs with ActiveJob, and build real-time features using WebSockets and ActionCable. Test your applications as you write them using the built-in unit, integration, and system testing frameworks, internationalize your applications, and deploy your applications easily and securely.
Rails 1.0 was released in December 2005. This book was there from the start, and didn't just evolve alongside Rails, it evolved with Rails. It has been developed in consultation with the Rails core team. In fact, Rails itself is tested against the code in this book.
All you need is a Windows, Mac OS X, or Linux machine to do development on. This book will take you through the steps to install Rails and its dependencies. If you aren't familiar with the Ruby programming language, this book contains a chapter that covers the basics necessary to understand the material in the book.