Rails 4 Directory Structure

Datum:

When you generate a new Rails 4 application, it creates an entire directory structure together with what seems at first sight to be a bewildering collection of files.

Some of you who are new to Rails may be wondering what all those generated files and directories are doing.

Rails generates an application by adhering to two great principles: It emphasizes convention-over-configuration, meaning it makes intelligent choices about what it thinks you want, and it organizes code by adopting the Model-View-Controller (MVC) architectural pattern.

The Structure of a Rails 4 app

This short blog post gives an overview of the most important folders of a new Rails 4 application and describes the purpose of some key folders and files.

First of all open your terminal or iTerm2 in my case and check Ruby and Rails version installed on your system.

Check Ruby Version

  
  ruby -v
    => ruby 2.3.1
  
  

Check Rails Version

  
  rails -v
    => Rails 4.2.6
  
  

I like to to use MySQL database instead of default SQLite which is not intended to be used as a production grade database.

Check MySQL Version

  
  mysql --version
    => mysql  Ver 14.14 Distrib 5.7.13, for osx10.11 (x86_64) using  EditLine wrapper
  
  

Now is time to generate new Rails 4 app.

Generate new Rails app with MySQL database

  
  rails new sample_app -d mysql
  
  

The above command generates the directory structure, which I describe below.


I hope this short tutorial gave you a quick introduction to Rails directory structure. Please feel free to contact me if you have any questions, comments or suggestions.

 

Máte-li dotaz nebo připomínku k tomuto článku, kontaktujte mě prosím zde.


  |    |