<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alessandro</title>
    <description>The latest articles on DEV Community by Alessandro (@simonini).</description>
    <link>https://dev.to/simonini</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F75206%2Fe30b3545-9d16-4b85-86c2-8d7fd8c9f608.jpeg</url>
      <title>DEV Community: Alessandro</title>
      <link>https://dev.to/simonini</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/simonini"/>
    <language>en</language>
    <item>
      <title>Ruby On Rails Best Practice 2020 (for us)</title>
      <dc:creator>Alessandro</dc:creator>
      <pubDate>Thu, 16 Apr 2020 08:39:56 +0000</pubDate>
      <link>https://dev.to/simonini/ruby-on-rails-best-practice-2020-for-us-341i</link>
      <guid>https://dev.to/simonini/ruby-on-rails-best-practice-2020-for-us-341i</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hi, I'm Alessandro and I'm a member of the dev team &lt;a href="https://www.rubynetti.it/" rel="noopener noreferrer"&gt;Rubynetti&lt;/a&gt;.&lt;br&gt;
We are based on Earth, Europe, Italy, Venice; we are a team of 3.&lt;br&gt;
We are 1 senior, 1 almost senior and 1 junior.&lt;/p&gt;

&lt;p&gt;We write and maintain different web software for different companies.&lt;/p&gt;

&lt;p&gt;Last year I wrote an article with our conventions and best practices.&lt;br&gt;
This year I choose &lt;a href="https://dev.to"&gt;dev.to&lt;/a&gt; to write it down.&lt;/p&gt;

&lt;p&gt;I hope that this gives us more feedback so we can improve our practice.&lt;/p&gt;

&lt;p&gt;These are the conventions and references we are using this year (2020) for our projects with Ruby On Rails. Some of these references come from the past. Others are a work in progress.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Boring Rest
&lt;/h2&gt;

&lt;p&gt;This is our big principle when we write web applications.&lt;br&gt;
Boring, conventional and predictable code it's the first and most important point to make easy to maintain complex Rails application.&lt;br&gt;
Became more important when writing code with a team.&lt;br&gt;
From this point of view &lt;strong&gt;Derek Prior&lt;/strong&gt; is our guru.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://speakerdeck.com/derekprior/in-relentless-pursuit-of-rest" rel="noopener noreferrer"&gt;In relentless pursuit of rest - Derek Prior&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.brianemory.com/rails-in-the-pursuit-of-writing-boring-code-5d04fee10470" rel="noopener noreferrer"&gt;Rails in the pursuit of writing boring code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://jeromedalbert.com/how-dhh-organizes-his-rails-controllers/" rel="noopener noreferrer"&gt;How to DHH organizes his rails controllers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Frontend
&lt;/h2&gt;

&lt;p&gt;We use a mix of &lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Vue&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://stimulusjs.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Stimulus&lt;/strong&gt;&lt;/a&gt;.&lt;br&gt;
When things are easy we use stimulus.&lt;br&gt;
When things are complex we use vue.&lt;br&gt;
For the moment we avoid SPA and we prefer to use vue as a widget handler.&lt;br&gt;
We used SPA and vue-routing only for one side-silly-project: a web card game about Venice society.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Test
&lt;/h2&gt;

&lt;p&gt;We use the standard Rails suite test.&lt;br&gt;
We use it with fixtures.&lt;br&gt;
Everything very normal.&lt;br&gt;
When we call external API we use VCR gem.&lt;br&gt;
Our test is generally short.&lt;br&gt;
We don't like and we don't use mocks and stuff like that.&lt;br&gt;
Too much code to write and maintain.&lt;br&gt;
We use a lot of rails short controller and model test.&lt;br&gt;
Sometimes we start from a test, other times we explore the situation before and write the test after.&lt;br&gt;
We like tests and we suggest everyone use it.&lt;br&gt;
They save our codebase from a lot of bugs and give us confidence when we change stuff.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Interactors
&lt;/h2&gt;

&lt;p&gt;Last year we start to use interactors.&lt;br&gt;
We were in the situation of having big fat models.&lt;br&gt;
A lot of concern. And this gives us headaches.&lt;br&gt;
The interactors seem to use a well-structured way to resolve the issue.&lt;br&gt;
Some times we use also PORO object but we like structured and conventional ways to force to write good and concise stuff.&lt;br&gt;
There are different and clever alternatives.&lt;br&gt;
We choose &lt;a href="https://github.com/AaronLasseigne/active_interaction" rel="noopener noreferrer"&gt;ActiveInteraction&lt;/a&gt; because it's easy to integrate inside Rails projects and can handle form errors.&lt;/p&gt;

&lt;h3&gt;
  
  
  How we use it?
&lt;/h3&gt;

&lt;p&gt;When things are easy we NOT use interactors and we use standard Rails Way.&lt;br&gt;
We like simple things and we like to avoid writing too much code.&lt;br&gt;
Sometimes the thins became complex.&lt;br&gt;
When this happens we use interactors.&lt;br&gt;
Our rule is similar to the Ruby Style Guide.&lt;br&gt;
We try to avoid class more length than 100 lines and methods with more than 10 lines).&lt;br&gt;
We like short methods and short classes.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Filter and callback
&lt;/h2&gt;

&lt;p&gt;We don't like and we don't use it. Sorry DHH.&lt;br&gt;
It's the only thing that we don't like about Rails.&lt;br&gt;
I promise. &lt;br&gt;
The problem is that we think that can be very dangerous because they hide complexity and the flow of the code.&lt;br&gt;
Sometimes someone can forget the callback and can generate a lot of problems with data mailer etc.&lt;br&gt;
We use it only in some rare cases when the convenience is big or when we take a legacy project and refactor are too big.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Gems
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Haml \ Slim&lt;/li&gt;
&lt;li&gt;Pundit (we say goodbye to Cancancan because we like simple things)&lt;/li&gt;
&lt;li&gt;Devise&lt;/li&gt;
&lt;li&gt;Webpacker \ Vite&lt;/li&gt;
&lt;li&gt;Ransack&lt;/li&gt;
&lt;li&gt;Filterrific&lt;/li&gt;
&lt;li&gt;ActiveInteraction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;New features of Rails 6&lt;br&gt;
We like e we use a lot 2 new features of Rails:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ActionText with Trix editor&lt;/li&gt;
&lt;li&gt;ActiveStorage instead Paperclip (sometimes we prefer carrierwave)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Mailer organization
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://ricostacruz.com/til/rails-mailer-race-conditions" rel="noopener noreferrer"&gt;Params for mailers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our best practice in the past:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.rubynetti.it/i/rails-best-practices-2019" rel="noopener noreferrer"&gt;Rubynetti Best Practices 2019&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;N.B. This document is working in progress.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>vue</category>
      <category>testing</category>
    </item>
  </channel>
</rss>
