Stemming from my last post, I just wanted to give a quick overview about what exactly Rails generated when you executed the Rails 'new' command
Start clicking around in all the files and see what they all contain. Make sure you familiarize yourself with all these files because every time you work with a Rails project, this is exactly how its going to look like.
Let's first bring our attention to the app folder and all the sub-directories that it contains.
- app
- assets
- controllers
- helpers
- mailers
- models
- views
In my head( and probably everyone else) this is the meat of the entire Rails project because it controls all the logic that your rails apps will do. It will contain all the models, all the controllers, and all the views that will be shown to the user. Naturally, you will spend most of your time in this folder. Now lets take a closer look at what the app folder contains.
If you have already clicked on the 'assets' folder you will find that it has even more folders. As you can see, there is space for images, javascript files, and some stylesheets!
Here is an example of an almost finished Rails application that contains stylesheets and javascript files for each controller/view that you will eventually generate.
Now we come to the 'controller' folder that has the logic to 'talk' between the models and the views. Let's say that you have an article 'model' that contains all the characteristics of an article (:title, :body, :author). A 'controller' will have an action to 'Read' all the articles from the model(actually from the database since every model contains a table in the database), store it in a variable and give it to the 'view' to display them on the screen(It's a bit more involved, but this is just the start!)
Here is an example of an almost finished Rails application that contains the controllers. Not every model has to have a controller. Also, remember that controllers are usually very lean( don't have too much logic)!
Next we move onto the helpers, which I've only used sparingly, but it is there to put in some logic for the 'view'. In case you ever have very large chunks of ruby code in the view, just know that you can encase that code in a function and place it in here
Now comes mailers! There are a lot of times when a website needs to send emails automatically. Through the mailers we can set exactly that type of functionality. I'll show you how to do it at some later time.
Now here comes the models, which are a little chunky with the logic, but it's okay, everyone still loves models because they are the basis for what we work with in our application. Now the model is pretty cool because you can think about anything in real life and create a model from it. An Article has (:title, :body, :author), a User has(:email, :name, :password, :Profile), a Profile has (:birthday, :fave_color,...). All models have a table in the database and they can have relations to each other!
Here is an example from an almost finished application
Finally, the last folder in the list is the views. It is precisely what you might think it is, which is the folder that contains all the files of html with embedded ruby code that come together to show a user your site!
Here is an example of something you might eventually see in the one of the view sub-folders
That concludes most of the app folder. I will eventually write about the rest of the files that Rails generated just to clear things up. Also, if you find anything confusing or just downright wrong, please notify me in the comments.