Search code examples
ruby-on-railsruby-on-rails-3rubygemsmessaging

How to count unread messages in Ruby on Rails 3


I'm using the gem mailboxer.
Can anyone show me how to count the number of unread messages in inbox?

I tried:

<%= current_user.mailbox.inbox.unread.count %>

but I get

'ArgumentError in Messages#received wrong number of arguments (0 for 1)'

Solution

  • With version 0.10 :

    @user.mailbox.receipts.where(read:false).count
    

    With version 0.11, I think it would be (tough I havn't tested it)

    @user.mailbox.receipts.where(is_read:false).count