先上图:
从图中可以看出,从浏览器请求到控制器响应一段代码给浏览器,整个流程一般情况下为8步:
- The browser issues a request for the /users URI.
- Rails routes /users to the
index
action in the Users controller. - The
index
action asks the User model to retrieve all users (User.all
). - The User model pulls all the users from the database.
- The User model returns the list of users to the controller.
- The controller captures the users in the
@users
variable, which is passed to theindex
view. - The view uses embedded Ruby to render the page as HTML.
- The controller passes the HTML back to the browser.3