Rails is difficult and painful! Ⅱ

I don't know the location of the file

First this! I had an analog mind, and I didn't know how the files of the app created by rails new were structured. It's all * alphabet *.

I wrote everything on paper. Yes, everything from app to README.md.

alt

I think it looks like this at first. This time, let's check where the main files are located when creating the application that you want to understand first. Other than that, you will gradually understand it later, so don't rush.

** app ** at the top left of the image This is the body of the application.

app is an abbreviation for application. Of these, the first four you need are assets, controllers, models, and views. Each is a group of files that control page decoration, operations, data, and screen display.

alt

assets

** Contains items related to page decoration. ** ** alt I think there are 4 folders in assets.

-** config : Contains Javascript settings, etc. - images : Put the images used for embedding etc. - javascripts : Contains the Javascript code. - stylesheets **: Contains CSS.

controllers

Contains various controllers that run the application. alt

-** application_controller : Exists from the beginning. It is a controller common to all applications. - Below **: This is a controller I created.

models

Contains various models that handle data. alt ――Basically I make everything myself.

views

Contains various HTML. The folder name matches the controller name. The users in this come from = users_controller. alt

Next is config. Contains various configuration files.

The first thing you want to know is routes.rb alt

routes.rb (roots)

Roots, that is, multiple routes. It's like a way to connect things that move apps, such as controllers and models.

Next is db. Contains various database related files.

alt What you need to know is migrate

migrate

It contains the database design. alt

Finally, Gemfile and Gemfile.lock.

alt These two are used when installing various functions in the application.

--Gemfile: A place to describe and store functions called gems (packaged like apps) --Gemfile.lock: It is regenerated every time you install a gem, and the information (version etc.) of the gem used in this application is displayed and fixed.

Summary

This time I organized the location of the files. The first thing I want to remember is only ** 8 **. Assets, controllers, models, views in the app routes.rb (roots) in config migrate in db And Gemfile and Gemfile.lock.

What role file is in which file? I think it will be much cleaner if it can be organized.

Recommended Posts

Rails is difficult and painful!
Rails is difficult and painful! Ⅱ
Rails and FormData
Code that is difficult to debug and parse
Rails valid? And invalid?
Rails is Owakon www
Understanding ruby's "|| =" specification and what is Rails presence method?
[Rails] What is the difference between redirect and render?
What is Rails gem devise?
[Rails] What is the difference between bundle install and bundle update?
[Rails] N + 1 problems and countermeasures
Rails: Difference between resources and resources
[Rails] require method and permit method
Rails "render method" and "redirect method"
Rails Tutorial Records and Memorandum # 0
rails path and url methods
Introducing Bootstrap and Font-Awesome (Rails)
[Rails] strftime this and that
Rails web server and application server
[Rails] fields_for is not displayed
What is Microservices? And Microservices Frameworks
What is Rails Active Record?
[Rails] Why is it render if save is successful and redirect_to fails?
[Rails] Save start time and end time
Enable jQuery and Bootstrap in Rails 6 (Rails 6)
[Rails] Difference between find and find_by
[Rails] Validation settings and Japanese localization
Rails model and table naming conventions
rails AWS deployment is not reflected
Remove "assets" and "turbolinks" in "Rails6".
CRUD features and MVC in Rails
[Rails] Differences and usage of each_with_index and each.with_index
Project ruby and rails version upgrade
Data is not registered in Rails.
This problem is soberly difficult ... (Ruby)
Consideration about Rails and Clean Architecture
[rails] Difference between redirect_to and render