Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

model view controller - What is MVC in Ruby on Rails?

Could someone please explain MVC to me in Ruby on Rails, in layman terms. I am especially interested in understanding the Model in MVC (can't get my head around the model).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Some background, MVC is a (compound) design pattern and was developed in 1979 by Trygve Reenskaug (Smalltalk).

True MVC was primarily planned for use in n-tier (non web) systems and it splits a system into 3 distinct parts, a Model, View and Controller

The Model

  • Contains data for the application (often linked to a database)
  • Contains state of the application (e.g. what orders a customer has)
  • Contains all business logic
  • Notifies the View of state changes (** not true of ROR, see below)
  • No knowledge of user interfaces, so it can be reused

The View

  • Generates the user interface which presents data to the user
  • Passive, i.e. doesn’t do any processing
  • Views work is done once the data is displayed to the user.
  • Many views can access the same model for different reasons

The Controller

  • Receive events from the outside world (usually through views)
  • Interact with the model
  • Displays the appropriate view to the user

** Classic MVC is not suited to web applications, as the model cannot send all changes to the view in an observer fashion (the view is a web page). The Model2 was introduced to overcome the changing infrastructure by JSP team in 90s . MVC Web frameworks are really not MVC, but Model2 (this is true of Ruby on Rails).

Here is a description of GUI patterns including MVC from the master, Martin Fowler GUI Architectures

The best book I have found so far is Agile Web Development with Rails. It begins by assuming no knowledge, and is quite comprehensive.

Hope this helps to shed some light for you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...