Create an official repository of patterns similar to the Rails Guides, but with a focus on solving common tasks with the framework.
Especially for newcomers, it can be daunting to find idiomatic ways to leverage the framework to solve common problems. For example, if one googles for "how to do authentication in Rails", one gets the recommendation to use the Devise gem (and lots of other blog articles). However, as an experienced Rails developer, we know that implementing a basic login can be written with a few lines of code - without external dependencies. I believe having an official platform to look up such solutions could improve developer velocity, junior confidence, code quality and even security.
Aside from helping to establish common approaches for common problems, such a site could also help to surface the existing documentation. For example, if one tries to build a user form with nested attributes, finding a trustworthy resource is hard. However, if one knows about the documentation of ActiveRecord::NestedAttributes::ClassMethods
and ActionView::Helpers::FormBuilder#fields_for
the problem becomes almost trivial. On the proposed platform, we could show one use case – from model to view – and link to the aforementioned docs for more information.
I believe that such a platform could help promoting Ruby on Rails.
- Improve the learning curve for beginners (by avoiding juniors having to swift through outdated blog articles/stack overflow comments)
- Speed up development by establishing a well-curated, go-to reference for discovering common solutions
- Enhance security by promoting proven, lightweight solutions (ideally free of external dependencies)
- Improve code readability by providing recognizable patterns
- Reduce uncertainty & arbitrariness which solution to choose by providing a trustworthy and up-to-date resource
Non-Goals:
- It should not be a place to promote dogmatism (all solutions are just recommendations and show their trade-offs)
- It should not promote particular gems, companies or developers
- It should not be an endless pool of pages – rather concise and reduced to a single solution per problem
Moderation The Rails Core Team has done a tremendous job in moderating the framework's functionality, API and documentation. Over the last years/decades, the community has written excellent guides which are promoted on www.rubyonrails.com
. For such a pattern platform, a similar scrutiny by a moderation team would be necessary.
Format My first thought was to present the patterns similarly to software design patterns (Definition, Usage, Structure, Example), but we may find that tutorials, screencasts or other formats might suit better.
Dependencies The goal is to solve problems with as few external dependencies as reasonable/possible. Developers can read the patterns, understand how an implementation works and employ them in their applications. Limiting the usage of gems allows the developers to weigh the trade-offs between different approaches and if the usage of external gems is worth the dependency.
Guidelines Getting to a minimal and consistent choice of solutions will be difficult and require much thought. We could setup guidelines as to which solutions/alternatives are preferable (e.g. "no external dependencies").
Credibility I believe this platform – once established and sufficiently filled – should be accessible via the Rails website's main menu (similar to guides) to emphasize the official nature of the platform. I believe that it would be beneficial if the patterns were hosted under a subdomain of rubyonrails.org. This would maximise its credibility and establish the official nature of the collection.
Patterns Here are some more ideas on what I mean by common patterns: login/authentication, Dockerized environment, deployment via mrsk/capistrano, implement a wizard-style form, nested forms, forms without persistence (form objects), pagination/filtering/searching of records, simple full text search, testing a feature (unit test -> system tests), styling setup with tailwind.
Differentiation The line between the existing Rails Guides and the aforementioned patterns is thin. I believe that the Guides show how to use framework's (core) functionality, where the patterns could demonstrate how to tie different framework components together to solve common (more complex) problems. This is certainly a good point for discussion.
Similar Projects Ryan Bates' Rails Casts did tremendous work in teaching concepts in rails. Unfortunately, most casts are now outdated. Also his scope was much wider the this proposal.
A long time ago, there was a book called Rails Recipes. This was a compendium of nice patterns similar to what I imagine here. Unfortunately, the book is about Rails 3.