Reputation: 207
I'm rendering a todo list for a user like so
<%= render @user.todos %>
What I'm trying to figure out is how to show only the ones that have been marked as completed.
Is this something that I should be doing in a controller or model, or is it ok to filter something like that in a view?
Upvotes: 1
Views: 208
Reputation: 37507
sounds like a named scope on the todo model which returns completed todos so you can then do
<%= render @user.todos.completed %>
Upvotes: 3
Reputation: 2576
The logic should always go into your Model.
You should create a :scope (rails 3) or :default_scope (Rails 2) in your model and call it in the View directly. Something like completed_todos and then you can call @user.completed_todos. You simply set completed = true in the scope.
Hope this helps.
Upvotes: 1