0

I'm trying a couple things to find conversations where not all messages have been deleted and it's not working.

Here's one implamentation:

def index  
    @conversations = @mailbox.conversations.delete_if do |c|
        receipts = c.receipts_for @master
    return (receipts.where(deleted: true).count == receipts.count)  
    end
    @conversations = @conversations.page(params[:page_1]).per(9)
end

I've also used .find_each instead of delete_if.

Here's the error I'm getting on my view

ActionView::Template::Error (undefined method `first_page?' for nil:NilClass):

Update: I removed return and now its showing:

NoMethodError (undefined method `page' for #):

monty_lennie
  • 2,871
  • 2
  • 29
  • 49

1 Answers1

0

The index method is exited as soon as it hits return

Try removing the return keyword.

Edit, re: pagination

When you use delete_if the resulting object will be an Array. Kaminari doesn't work by default with arrays. See this link.

So, you would need to do something like this: @conversations = Kaminari.paginate_array(@conversations).page(params[:page_1]).per(9)

A better solution than using delete_if would be do put together a query that returns exactly what you want as an ActiveRecord::Relation object.

I'm not sure exactly what that would look like off the top of my head. Might make a good separate question.

johnnycakes
  • 2,440
  • 2
  • 28
  • 36