Marnen Laibow-Koser wrote:
> Example:
> # controller
> def my_action
>   @person = Person.find(params[:id])
> end
> 
> #my_action.html.erb
> Good: <%= @person.name >
> Bad: <% @person.save! =>
> Unspeakable: <% @people = Person.all %>

Good example. I just want to throw in a couple more twists and see what 
you think.

1. What about methods on models that change themselves in some way?

<%= @post.last_viewed_at %>

Suppose the last_viewed_at method returned a previously stored time, 
then updated the model to store a new current time. Maybe a bad example, 
but I hope you get my meaning.

2. What about aggregating class methods like count, sum or avg?

<%= Person.count %>

Obviously a class methods and does touch the database. I assume it would 
be better to let the controller deal with stuff like this.

Controller
  @person_count = Person.count

View
  <%= @person_count %>

Thoughts anyone?
-- 
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.

Reply via email to