Synopses & Reviews
“Foy is a gifted writer and his descriptions of the philosophies that( impacted the design and implementation of Merb are definitely useful to( everyone affected by the changes in Rails 3.”
–Obie Fernandez, Series Editor
The Expert Guide to Building Merb Applications
Thousands of Ruby and Rails developers are discovering the extraordinary scalability, agility, flexibility, and performance offered by the new Merb MVC framework. The Merb Way is the first comprehensive guide to using, extending, and deploying Merb. Like the bestseller The Rails Way (Addison-Wesley, 2008), this book can either be read cover-to-cover as a tutorial or used for modular coverage that makes it an ideal task reference. Foy Savas systematically covers everything developers need to know to build production-quality Merb applications, offering detailed code examples for jumpstarting virtually any project.
Savas is not only involved in the Merb project as an open source contributor: He uses Merb every day as a professional developer. Drawing on his extensive practical expertise, he delves deeply into the Merb framework’s architecture and source code, revealing its elegance and offering powerful best practices for using it. To maximize this book’s practical value, he also covers the tools most widely used alongside Merb, including the DataMapper ORM, the RSpec tester (and associated behavior-driven development techniques), and several leading Merb plugins.
The Merb Way will help you
- Master Merb innovations that will be incorporated into Rails 3
- Understand the fundamentals of Merb development, one step at a time
- Use Merb’s sophisticated application router to guide incoming requests
- Explore the Merb stack, master its configuration options, and dive into its internals
- Use Merb controllers to integrate application code, handle responses, and manage sessions, filters, and exceptions
- Build templates with both ERB (Erubis) and HAML
- Use the DataMapper ORM to represent object properties and behaviors
- Learn best practices for RESTful development with Merb
- Leverage Helpers to simplify many common development tasks
- Refactor code, encapsulate it in gems, and share it across multiple applications
- Customize the responses your application sends to each user
- Gain a deep, practical understanding of Merb plugins and extensibility
- Authenticate users with Merb’s modular authentication plugin
- Configure, generate, describe, and test Merb mailers
- Use the merb-parts gem to create component-like regions on Web pages
- Cache content to relieve stress on Web servers
- Make the most of Behavior Driven Development and testing with RSpec
About the Author
Foy Savas is both a contributor to the Merb project and one of Merb’s earliest adopters. He has applied the Merb framework in both large and small production applications. Foy is director at Assembly (http://assemb.ly), a Boston-based consulting firm focused on connecting brilliant people with innovative ideas. In the past he has served as CTO for a large health and fitness site and as a lead consultant for several white-labeled Web applications.
Table of Contents
Foreword xix
Acknowledgments xxi
Merb pastie xxiii
Introduction xxvii
About the author xxxi
Chapter 1: Fundamentals 1
1.1 Generating a new application 1
1.2 The layout of a Merb application 2
1.3 Interactive Merb 9
1.4 Merb configuration 12
1.5 Understanding the Merb stack 20
1.6 An overview of Merb internals 27
1.7 Conclusion 35
Chapter 2: Routing 37
2.1 How Merb routing works 38
2.2 Router configuration 43
2.3 Checking routes 45
2.4 Match rules 50
2.5 Registering routes 54
2.6 Other route settings 57
2.7 Resource routes 60
2.8 Conclusion 64
Chapter 3: Controllers 65
3.1 From request to controller 65
3.2 The controller classes 68
3.3 Custom controller classes 75
3.4 Filters 79
3.5 Redirects 84
3.6 Exceptions 87
3.7 Rendering templates 89
3.8 run_later 97
3.9 Sending and streaming 97
3.10 Conclusion 99
Chapter 4: Views 101
4.1 ERB 101
4.2 Haml 105
4.3 Merb view templates 109
4.4 Partials 111
4.5 Conclusion 112
Chapter 5: Models 113
5.1 Configuration 113
5.2 Model classes 115
5.3 Properties 118
5.4 Associations 132
5.5 CRUD basics 140
5.6 Hooks 154
5.7 Plugins 155
5.8 Conclusion 165
Chapter 6: Helpers 167
6.1 Truncate helper 167
6.2 Numeric helpers 168
6.3 Date and time helpers 171
6.4 Cycle helper 176
6.5 Tag helpers 177
6.6 Form helpers 179
6.7 Conclusion 192
Chapter 7: Slices 193
7.1 Slice development 193
7.2 Slice usage 201
7.3 Conclusion 203
Chapter 8: Sessions 205
8.1 How sessions work 205
8.2 Configuration 206
8.3 Storing sessions 207
8.4 Request access 219
8.5 Controller access 220
8.6 Conclusion 220
Chapter 9: Authentication 221
9.1 Auth core 221
9.2 Auth more 237
9.3 Auth password slices 245
9.4 Conclusion 251
Chapter 10: Mailers 253
10.1 Configuration 253
10.2 Using mailers directly 255
10.3 Mail controllers 257
10.4 Testing 261
10.5 Generation 261
10.6 Conclusion 262
Chapter 11: Parts 263
11.1 Parts controllers 263
11.2 Invoking actions 266
11.3 Generation 267
11.4 Conclusion 267
Chapter 12: Caching 269
12.1 Configuration 269
12.2 Caching basics 271
12.3 Caching helpers 274
12.4 Conclusion 278
Chapter 13: Testing 279
13.1 Rake tasks 279
13.2 Spec files 282
13.3 Model specs 283
13.4 Request specs 285
13.5 Request helper 289
13.6 Request matchers 290
13.7 RSpec extensions 292
13.8 Miscellaneous extensions 294
13.9 Conclusion 295
Afterword 297
Index 299