MVC is a software architecture pattern, that is heavily embraced by Ruby on Rails.
It stands for Model - View - Controller.
The model is used for modelling the data structure of your objects and how they relate to each other. E.g.: A blog might have blogposts and comments as two models. Blogposts have many comments. A comment belongs to a blogpost. Models are also used for validations. E.g. a blogpost might validate the presence of a title. The attributes of a model are not declared in the model, they are read from the database on application startup.
The controller declares all the actions, you want to be able to call from the browser. You load all data to be displayed to the user in the controller code. Typical actions are the CRUD actions, which contain create, read, update and destroy. To create a record or to update it, we need another action to display the user a form to be able to enter data. These are the new and the edit actions, respectively.
The views describe the content of the HTML pages that are delivered to the user. To be able to get some Ruby into HTML, views are written in ERB, that stands for embedded Ruby. It is HTML extented by Ruby tags inside brackets <%= #RUBY-CODE# %>.
Ruby on Rails has the convention, that instance variables in controllers, e.g. @blogpost or @blogposts, are available in the views
<ul>
<% @blogposts.each do |blogpost| %>
<li><%= blogpost.title %></li>
<% end %>
</ul>
MVC is a software architecture pattern, that is heavily embraced by Ruby on Rails. It stands for Model - View - Controller.
<%= #RUBY-CODE# %>
. Ruby on Rails has the convention, that instance variables in controllers, e.g.@blogpost
or@blogposts
, are available in the views