On 10 March 2010 17:19, Marnen Laibow-Koser <[email protected]> wrote: > Colin Law wrote: >> On 10 March 2010 15:15, Marnen Laibow-Koser <[email protected]> >> wrote: >>> Sharagoz -- wrote: >>>>>> If it is literally something as simple as MyArray.all I believe there >>>>>> is nothing wrong with calling the model direct from the view. >>> >>> But you are wrong. �The view should never, ever, ever touch the >>> database. >> >> Is it considered ok to call model methods if they do not touch the db, >> or are model methods forbidden also? > > I think it is appropriate for the view to call methods on the objects > passed in by the controller, provided that these methods do not change > the model or touch the database. > > Example: > # controller > def my_action > �...@person = Person.find(params[:id]) > end > > #my_action.html.erb > Good: <%= @person.name >
What about <%= @person.group_name %> where Person belongs to Group and group_name is an instance method of Person def group_name group.name if group end > Bad: <% @person.save! => I would class the above as the unspeakable one actually. > Unspeakable: <% @people = Person.all %> 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.

