This is a lot of logic for a view. What if you moved the collecting of grocery_list_items to a method on GroceryList?