The Ruby on Rails directory structure is created with the terminal command
rails new <projectname>.
The directory structure is the basic organisation of the software project. Its how Rails knows where to find the files.
Rails generates the project directory structure.
If you run the command
rails new blog, a new project (and directory) will be created named blog.
Typing the command
cd blog and
ls will then show the directory structure.
app config.ru Gemfile.lock package.json README.md tmp
Rails uses the Model View Controller model (MVC).
HTTP requests are given to a controller class
A controller process it, communicates with the database (model)
app/models and finally returns a template (view)
The flow is:
URL request → Controller → Model → View → Web browser.
Rails creates many directories. So what’s each directory for?
|app||Apps components: apps business logic, controllers and views.|
|app/controllers||Controller classes. Rails uses the Model-View-Controller (MVC) model.|
|app/helpers||Helper classes for models, views or controllers.|
|app/models||Database code. Model in the MVC model.|
|app/views||Templates to display. The Views in the MVC model.|
|tmp||Rails uses this for temporary files during execution.|
|public||The public directory for your Rails app, similar to the public directory in a web server like Nginx or Apache.|
|config||Config files for your app|
|Rakefile||Like a Makefile, build and packages Rails code|