What are the most common Ruby on Rails antipatterns and how to avoid them?
There are two main anti-patterns I've seen in a lot of Rails code:
A lot of "heavy lift" in the looks. Everything more complicated than a simple iteration over assemblies or string interpolation should be in the helpers or methods of the model. Do not request model objects, do not create large JSON arrays, or do not update session variables from your ERB templates.
Model objects that are not used for scripting or API implementation. Your models define the domain semantics for your application. You should be able to run a script / console or write service API wrappers that reuse existing functional model methods to manage all key data in your application. The functionality of the controller is available only in the HTTP request / response cycle, which is only part of any fully functional site life cycle.
Do not learn Ruby.
USE if WITH else
antipattern:
unless is_the_weekend? do stuff that you do during the week else do stuff that you do on weekends end
Alternative:
if is_the_weekend? do stuff that you do on weekends else do stuff that you do during the week end
Alphabet Soup?
(There are no declared and meaningless variable names, which leads to almost unreadable code)
The name of the template comes from the names of variables like "a", "b", "c", "d", etc.