Andrew France wrote: > On 09/02/10 01:32, Marnen Laibow-Koser wrote: >> 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. >> > > It's quite common for controllers to have methods which are not directly > actions.
Not in my applications. It's inappropriate to put that much logic in the controller. The only exceptions are things like current_user, which can't really live anywhere else, and current_object, which is simply a refactoring of controller code. Anything else belongs in a model or a helper. > By default they are accessible from URLs but it's good practice > to remove the default route anyway. Plus they could be set to protected > (workaround probably required) or hidden with hide_action. Just don't have them. It's conceptually wrong for the way Rails works. > > >>> end >>> >> controllers? >> > > The code above already works, if that answers your question. > > As for using partials, well one of reasons for using methods is that > you're making the contract between the view and the controller more > explicit. Perhaps, but it couples the view to one controller, which is wrong. > You already have it with instance variables but I suppose > using unset instance vars to determine logic in views is a little easier > albeit less elegant. Don't do that much either. Use a helper... > > 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.

