Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Layered Design for Ruby on Rails Applications

You're reading from  Layered Design for Ruby on Rails Applications

Product type Book
Published in Aug 2023
Publisher Packt
ISBN-13 9781801813785
Pages 298 pages
Edition 1st Edition
Languages
Author (1):
Vladimir Dementyev Vladimir Dementyev
Profile icon Vladimir Dementyev

Table of Contents (20) Chapters

Preface 1. Part 1: Exploring Rails and Its Abstractions
2. Chapter 1: Rails as a Web Application Framework 3. Chapter 2: Active Models and Records 4. Chapter 3: More Adapters, Less Implementations 5. Chapter 4: Rails Anti-Patterns? 6. Chapter 5: When Rails Abstractions Are Not Enough 7. Part 2: Extracting Layers from Models
8. Chapter 6: Data Layer Abstractions 9. Chapter 7: Handling User Input outside of Models 10. Chapter 8: Pulling Out the Representation Layer 11. Part 3: Essential Layers for Rails Applications
12. Chapter 9: Authorization Models and Layers 13. Chapter 10: Crafting the Notifications Layer 14. Chapter 11: Better Abstractions for HTML Views 15. Chapter 12: Configuration as a First-Class Application Citizen 16. Chapter 13: Cross-Layers and Off-Layers 17. Index
18. Gems and Patterns 19. Other Books You May Enjoy

Separating domain and persistence with repositories

In Chapter 2, Active Models and Records, we discussed two object-relational mapping abstractions, Active Record and Data Mapper, and their differences. Rails obviously goes with the first approach, but that doesn’t mean we cannot derail and use Data Mapper concepts in our code.

To recall, the main difference between Active Record and Data Mapper is that Data Mapper separates models from persistence: models are just enhanced data containers, and other objects are used for querying and storing data (repositories and relations). Thus, there is a clear separation between the domain layer and domain services. This separation gives you more control over data access and transformation at the cost of losing Active Record’s (the library’s) simplicity.

Usually, switching to the Data Mapper paradigm in Ruby on Rails applications comes along with migrating to some other ORM instead of Active Record – for instance...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at AU $19.99/month. Cancel anytime}