HomeAboutBlogPortfolioTechNews Register Login

My Blog


As I have studied development I have learned that there is a lot to know. Everytime I learn something new, I realize there is much more I don't know.

Because I am learning, I may edit these blog posts multiple times.

I also may be incorrect on my understandings. So please feel free to create an account and use the comment section to point out where I am wrong. Also feel free to correct me on an grammatic errors.

Here are some things I have learned along the way!

Rails MVC

Rails Backend

For this post I want to talk about the basic structure of Ruby on Rails.  Rails is a MVC software architectural pattern. Where M stands for model, V for view, and C for controller. Most websites communicate with databases to pull information and display it to the user.  However, there are some that do not and those are called static pages. Rails though is a Ruby web application framework built to work with databases.

 

Controller

 

In order to control the information that is accessible from the database rails uses the MVC pattern.  When a user types in a web address it first goes to your routes. Your routes will direct you to a controller.  What is the controller’s job? Well it’s in the name. It controls a lot of the data flow of the application. It is the controller that will determine if the application will need to go to the database through the model to grab information or if it can just go directly and grab views to be displayed.  If it wasn't for the controller it would be easy for a hacker to grab whatever information they want from the database. Some information may be sensitive. For example credit card information. Also the controller helps to keep hackers from dumping anything they want into your database. It is important that when you code out your controllers you use best practices for security measures. 

 

Model

 

If the page that is being accessed is just a static page it will go straight to the views.  Otherwise the controller tells the model what it wants from the database. The model then fetches it from the database and sends it back to the controller. The Rails framework is set to allow the views to be able to pull the information it needs from the corresponding method in the controller.  I hope to discuss the controller methods in more detail in another post.  

 

Views

 

Just like the name controller, the name views is pretty self explanatory.  The views are the pages that are displayed to the end user in the browser. The views are created with HTML with embedded Ruby.  The embedded Ruby allows the views to display data that was grabbed from the database. The views will also use stylesheets which are typed in CSS code along with JavaScript to help with page layout and design.  

 

Example

 

Just in case you are still confused, I want to give an example.  Let’s say you visit a blog that is built using Ruby on Rails. Like this one!  When you select the blog you want to see, the routes will go to a method in a controller.  Typically a controller set up specifically and solely for the blogs. The naming convention used for a method the displays one blog, is show.  The show method in the blog controller will tell the model to go to the database and send back the specifically requested blog. The model will grab the blog from the database and send it to the controller.  The controller then will send the blog to a show view. The end user then can see the blog and joyfully read. Or read with distaste.  

Either way leave a comment and let me know what you think.  Feel free to tell me if you think I am wrong with anything. Or ask questions.


4f8e5232afadeaad2bc802100651d174
this is a test
Comment posted by Jason about 3 years ago