On Thu, Jan 26, 2012 at 3:37 PM, Colin Law <[email protected]> wrote: ...
> To me that looks more like something that should be called in the > controller and go into an @ variable for use in the view. The general > rule is setup data in the controller and display it in the view. TL;DR * controller only does "routing/decision" logic (render, error, redirect, ...) * views get their rich data from a presenter I feel less confident about this strategy. I have doubts over this code in the controller that is "pushing/pre-setting" data into e.g. a @user instance variable @user = User.include(:account).include(:address).include(:projects).find(params[:id]) of which a large fraction may remain unused and the specific usage may change over time. Suppose that we initially show a list of all the projects of the user in the show view, but later decide to not show that list in the first "show" view anymore (it could e.g. be shown later with an AJAX request when the user opens a projects tab). Then we would be always populating the @user with too much data, unless we think about removing that from the controller. I would prefer a method where the view "pulls" (only) the data that it needs, when it needs it, from ... (a presenter ??). A helper (in my opinion) is purely an html/decorator thing (as was also the feeling of the OP, If I understood correctly). Of course, the ActiveRecord::Relation helps to delay the actual SQL in certain cases (e.g. in the index view). But it does not remove the code complexity and potential inefficiency from the controller. I start to feel more that the controller does some "routing/decision" logic (render, error, redirect, ...), but that it should not really prepare the data for later views. The views should "pull" their data from a presenter. Does this make sense? Would it address the initial question from the OP? Peter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

