Maintainable Rails
$10.00
Minimum price
$12.50
Suggested price

Maintainable Rails

About the Book

Learn how to build a maintainable Rails application by using the rom-rb and dry-rb set of gems to your advantage. Move away from messy, traditional Rails code and move towards crisp, clean code.

The default structure of Rails applications hasn't changed all that much in over a decade. And with good reason: this directory structure makes it easy to jump into building a Rails application.

While I agree that this way is still extremely simple and great for getting started within a Rails application, I do not agree that this is the best way to organise a Rails application in 2018 with long-term maintenance in mind. A decade of Ruby development has produced some great alternatives to Rails' MVC directory structure that are definitely worthwhile to consider.

One alternative can be found in the combination of the rom-rb and dry-rb set of gems.

The `rom-rb` gems allow us to interact with a database with just as much ease as Active Record, but with the added benefit that persistence and business logic aren't bundled together in the same class.

The `dry-rb` gems allow for splitting the validation logic away from the business logic's class (dry-validation) and also provides a sensible alternative to the community-wide pattern of service objects (dry-transaction).

This book covers how you would go about integrating these gems into a brand new Rails application, building features in an iterative fashion, resulting in a maintainable structure for the whole application.

About the Author

Ryan Bigg
Ryan Bigg

Ryan has been writing books and documentation for programming languages for over a decade. These books have sold over 20,000 copies worldwide.

Ryan lives in the lovely coastal town of Warrnambool, Australia.

Table of Contents

  • Introduction
    • Who is this book for?
    • Acknowledgements
  • Preface
    • Where Rails falls down
    • Messy controllers
    • The problems with Active Record Models
    • Views
    • We can do better
  • Getting started with ROM and Dry
    • Application setup
    • Boot Configuration
    • Specifying the container automatically
  • Rails, meet ROM
    • Generating our first ROM-powered relation, migration, repository and model
  • Connecting a Rails controller with ROM
  • Showing a particular project
  • Validating projects during creation
    • A small interlude about that contributors method
    • Creating a validator
  • Let’s talk about service objects
    • Building our first operation class
    • Integrating the Projects::Create class with the controller
    • Refactoring the operation class one step further
  • Working with associations
    • Creating a tickets repository, relation, model and migration
    • Creating all the parts for users
    • The contributors method
  • Two kinds of views
    • Displaying contributors
    • The top_contributors database view
    • Summary
  • Epilogue
    • Tidbits
  • Homework
    • Finish the CRUD actions for the ProjectsController
    • Add a TicketsController
    • Add Devise to the application
  • Notes

The Leanpub 45-day 100% Happiness Guarantee

Within 45 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$10,589,243writing, 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), EPUB (for phones and tablets) and MOBI (for 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

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF, EPUB and/or MOBI files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub