Andrew France wrote: > Hi, > > I was thinking whether it would be more elegant for a view to call > methods on the controller rather than rely on instance variables.
The trouble with this is that controller methods are actions, not getters. > I'm > not really sure what the answer is so thought I would throw it out > here. > Perhaps with a basic DSL that makes it explicit what the controller is > setting, like: > > class BooksController < ActionController::Base > var :book do > Book.find(params[:id]) > end > end > > where var: > > class ApplicationController.. > def self.var(name, &block) > define_method(name, block) > helper_method(name) > # Perhaps memoize too? > end > end > > Does this violate the rule that the controller should be driving the > view? Yes. The controller just passes variables to the view. > Any major disadvantages you can see? Lots. Does the view even have the controller object in scope? Should it need to? What if you want to use the same partial with different controllers? If you want something like this done right, check out Mustache. > > Regards, > Andrew Best, -- Marnen Laibow-Koser http://www.marnen.org [email protected] -- Posted via http://www.ruby-forum.com/. -- 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.

