Ruby on Rails - Ruby on Rails MVC - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
What is Ruby on Rails MVC?
- The Model View Controller principle divides the work of an application into three separate but closely cooperative subsystems.
It basically works as following:
- Requests first come to the controller, controller finds an appropriate view and interacts with model which in turn interacts with database and send response to controller.
- Then controller gives the output to the view based on the response.
Learn ruby - ruby tutorial - learn ruby tutorial - model controller architecture in ruby rails mvc - ruby example - ruby examples - ruby programs
What is a Model?
- The models are classes in Rails. They interact with database, store data, handles validation, transaction, etc.
- This subsystem is implemented in ActiveRecord library.
- This library provides an interface between database tables and Ruby program code that manipulates database records.
- Ruby method names are automatically generated from database tables field names
What is a View?
- View represent data in a particular format in an application for the users.
- It handles HTML, CSS, JavaScript and XML in an application.
- They do what controller tells them.
- This subsystem is implemented in ActionView library.
- This library is an Embedded Ruby (Erb) based system which define presentation templates for data presentation.
What is a Controller?
- Controller directs traffic to views and models.
- It query models for data from the database and display the desired result with the help of view in an application.
- This subsystem is implemented in ActionController library.
- This library is a data broker sitting between ActiveRecord and ActionView.
Learn ruby - ruby tutorial - learn ruby tutorial - process of controller in ruby rails mvc - ruby example - ruby examples - ruby programs
Directory Representation of MVC Framework
- Assuming a standard, default installation over Linux, you can find them like this
- You will see subdirectories including (but not limited to) the following
- actionpack-x.y.z
- activerecord-x.y.z
- rails-x.y.z
Over a windows installation, you can find them like this
You will see subdirectories including (but not limited to) the following
Learn ruby - ruby tutorial - learn ruby tutorial - subdirectories view in ruby rails mvc - ruby example - ruby examples - ruby programs
ActionView and ActionController are bundled together under ActionPack.