<?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: Jaime Montes de Oca</title>
    <description>The latest articles on DEV Community by Jaime Montes de Oca (@jm2292236).</description>
    <link>https://dev.to/jm2292236</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%2F809396%2F14adb7db-dcd7-4076-988d-748d3a0dba7a.png</url>
      <title>DEV Community: Jaime Montes de Oca</title>
      <link>https://dev.to/jm2292236</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jm2292236"/>
    <language>en</language>
    <item>
      <title>Typical folder structure for a Ruby application using Sinatra and ActiveRecord</title>
      <dc:creator>Jaime Montes de Oca</dc:creator>
      <pubDate>Sun, 14 Aug 2022 17:49:36 +0000</pubDate>
      <link>https://dev.to/jm2292236/typical-folder-structure-for-a-ruby-application-using-sinatra-and-activerecord-169o</link>
      <guid>https://dev.to/jm2292236/typical-folder-structure-for-a-ruby-application-using-sinatra-and-activerecord-169o</guid>
      <description>&lt;p&gt;When writing a software application, &lt;em&gt;separation of concerns&lt;/em&gt; is very important, especially with object oriented programming. It is key that we use a folder structure that is easy to work with and clearly let us know where to put each file.&lt;/p&gt;




&lt;p&gt;This is a suggestion on how to make this folder structure when you are coding in &lt;strong&gt;Ruby&lt;/strong&gt; using &lt;strong&gt;Sinatra&lt;/strong&gt; and &lt;strong&gt;Active Record&lt;/strong&gt;. Each folder in this structure has a clearly defined responsibility as well as each file inside of them.&lt;/p&gt;

&lt;p&gt;Files in the root folder:&lt;br&gt;
&lt;strong&gt;Gemfile&lt;/strong&gt;: Lists all the gems that need to be installed for our application to run.&lt;br&gt;
&lt;strong&gt;Rakefile&lt;/strong&gt;: Contains code we create and use for common tasks we can run from the command line and also by requiring &lt;strong&gt;sinatra/activerecord/rake&lt;/strong&gt; we can have access to other useful tasks like &lt;strong&gt;db:migrate&lt;/strong&gt; or &lt;strong&gt;db:seed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Folders:&lt;br&gt;
&lt;strong&gt;app/models&lt;/strong&gt;: Here we put all our Active Record models, the core of our application because here we access and update the database responding to the user actions.&lt;br&gt;
&lt;strong&gt;app/controllers&lt;/strong&gt;: Following the software pattern known as &lt;a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller"&gt;Model-View-Controller&lt;/a&gt;, this folder contains the code for creating our API end points that are responsible for feeding the client app.&lt;br&gt;
&lt;strong&gt;config&lt;/strong&gt;: Code responsible for our environment setup. Here we define how to connect to the database and require files or gems needed by our application.&lt;br&gt;
&lt;strong&gt;db&lt;/strong&gt;: Has the different databases we are using for each environment (development/test).&lt;br&gt;
&lt;strong&gt;db/migrate&lt;/strong&gt;: Files to create/alter the database structure.&lt;br&gt;
&lt;strong&gt;db/seed.rb&lt;/strong&gt;: File that contains code to add sample data to our database. Here is a useful &lt;a href="https://github.com/faker-ruby/faker"&gt;gem for generating sample data&lt;/a&gt;. We can use the rake task &lt;em&gt;db:seed&lt;/em&gt; to add that sample data to the database.&lt;br&gt;
&lt;strong&gt;spec&lt;/strong&gt;: Contains all the test files.&lt;/p&gt;

&lt;p&gt;Following a well designed folder structure will make it easy to know where to put code depending of its responsibility, will help our application to grow under control and will help other developers to easily maintain the application in the future.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>sinatra</category>
    </item>
  </channel>
</rss>
