On Feb 8, 4:44 am, Andrew France <[email protected]> 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. 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? Any major disadvantages you can see?
I like the idea for several reasons, not the least of which is that we use methods in partials. This approach makes it easier to move stuff around. FYI - there's already a gem that does this with pretty much the same syntax you proposed: http://github.com/voxdolo/decent_exposure. Cheers, David > Regards, > Andrew -- 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.

