On 26 January 2012 16:38, Peter Vandenabeele <[email protected]> wrote: > 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?
I think the issue there is where there may be multiple ways of "viewing" the data. For example xml and html. In that case the conventional MVC concept is that the controller prepares the data then it goes off to an appropriate renderer which decides how to format it. In your example above with user projects, if only a subset of the projects is to be seen then it is up to the controller to make that subset available. Colin Colin -- 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.

