Rob Biedenharn wrote in post #968133: > On Dec 13, 2010, at 2:40 PM, Marnen Laibow-Koser wrote: > >>> class Post >> chaining out of the view, but at the cost of a completely unnecessary >> model method. >> >> If a calculation were being performed to get this value, I'd agree >> with >> defining a method. But I think accessor method chaining in the view >> is >> generally acceptable, particularly when it simply involves traversing >> already loaded associations. > > But I will remind you that the OP found that the problems came from > Posts that did not have an associated User. In such cases, post.user > will be nil and nil.empty? does not exist.
Right you are. I committed the cardinal sin of not considering what you wrote in light of the whole thread. Sorry. > Perhaps you meant to say > unless post.user.blank?, but if there are many places where a > post.user_name is used, the extra method avoids Law of Demeter > violations. (Or "Suggestion of Demeter" if you prefer.) I'm aware of that. I don't think the Law of Demeter is particularly helpful in Ruby. > > -Rob > Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org Sent from my iPhone -- 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 rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.