The Acts As Messageable allows communication between the models.
To use it, add it to your Gemfile:
gem 'acts-as-messageable'
-
rails g acts_as_messageable:migration
-
rake db:migrate
class User < ActiveRecord::Base acts_as_messageable end @user1 = User.first @user2 = User.last # user1 send message to user2 @user1.send_msg(@user2, "Message to user2", "Hi user 2!;-)") @user2.send_msg(@user1, "Re: Message to user2", "Hi there!:)") # Show inbox @user1.recv # Show outbox @user1.sent # Search message @user1.msg # all messages (in and out) @user1.msg(:from => @user2) # all messages from @user2 @user1.msg(:to => @user2) # all messages to @user2 @user1.msg(:id => 2) # message where message.id = 2
Copyright © 2010 Piotr Niełacny (ruby-blog.pl), released under the MIT license