From the course: Hands-On Introduction: Ruby on Rails
Understanding the application structure - Ruby on Rails Tutorial
From the course: Hands-On Introduction: Ruby on Rails
Understanding the application structure
- [Instructor] We are going to see the important parts of the structure of a Ruby on Rails application. The app folder contains the application's main code, including the main components of the MVC architecture, which are the following. The most important parts is the models, which are classes that represent tables in the database and encapsulate the business logic. The views, which are the HTML templates, they contain Ruby code and generate the final HTML. Finally, the controllers, which are classes that receive the requests, process data, and render the views. Here, we can also find the JavaScript folder. Inside, there's a controller sub folder with the controllers of stimulus, the Java squid framework included in Ruby on Rails 7. In the helpers folder, you can find Ruby models where you can add code reusable by views. In jobs, you can define code that runs in the background. And in mailers, there's the code that processes emails. Another important space is config. It contains application configuration files such as database.yml with the database configuration. Routes.rb, where the routes of the application are defined. Or application.rb, where the general configuration of the application is located. The DB folder contains files related to the database. The most important part is the migrations, which defines the changes. For example, creating new tables. For now, there's only a seeds file used to generate test data. In public are placed the public files, such as internal error templates, images, the fab icon, and the robots file. In test, there are automated test files, for example, unit tests called models, controllers, or integration tests. In vendor, there are the third party files used by the application. In the root, there are important files such as Gemfile and Gemfile.lock. They define libraries on which the application depends and their versions. In Ruby jargon, they're called gems. By following this structure, your application will stay organized and easy to navigate. Also, knowing each part of the application is for will allow you to work on it effectively.