Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Michael Hartl's book differencies between Rails 3.0 and Rails 3.2

I'm learning Ruby on Rails from Michael Hartl's book. I really enjoy this writing, structured and clear. Nevertheless, I have a question about chapter 3.3 differences between Rails 3.0 and Rails 3.2 versions:

  • The PagesController becomes a StaticPagesController
  • @Title is not anymore initialised in the controller, but in each page
  • The @Title variable is initialised through "provide" function, and used through "yield" function instead of simply inserting <%= @title %>

Is it for training reasons, or is it an updated best practice of RoR development?

like image 577
user1185081 Avatar asked Feb 02 '12 12:02

user1185081


1 Answers

The PagesController becomes a StaticPagesController

There is no reason. PagesController is fine. He did that maybe for clarity reason (?).

@Title is not anymore initialised in the controller, but in each page

This is for best practice/convention reason. Please take a look at the answer on this question Where does the meta content live in the MVC?

The @Title variable is initialised through "provide" function, and used through "yield" function instead of simply inserting <%= @title %>

Same answer as above.

Some people think that meta content such as title belongs to the view and thus should be set in the view, not in the controller.

The practical differences between provide and content_for are well explained here: http://api.rubyonrails.org/classes/ActionController/Streaming.html#module-ActionController::Streaming-label-Communication+between+layout+and+template

Please note that these changes are not specific to Rails 3.2 (except for provide that was introduce with stream in Rails 3.1).

like image 52
Damien Avatar answered Oct 14 '22 07:10

Damien