Need help with simple-private-messages?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

202 Stars 49 Forks MIT License 44 Commits 6 Opened issues


Rails plugin that provides basic private messaging functionality between the users of a site.

Services available


Need anything else?

Contributors list

= Simple Private Messages

Now Rails 3 compatible!

For Rails 2.3.x users there is an appropriately named branch that can be used.

This plugin provides basic private messaging functionality between the users of a site. It's not big on features but the idea is that it's nice and simple and light on resources.

It's not bound to specific model names and plays nice with will_paginate.

= Setup

Since there is no .gemspec for this, you must specify '0.0.0' as version in your Gemfile to make it install properly:

gem 'simple-private-messages', '0.0.0', :git => 'git://'

Then run

bundle install

First create the private message model by running the simpleprivatemessages:model generator, passing two parameters - the name you want to use for the Message model and the name of the User model.

For all examples in the readme, we will use Message and User.

rails generate simpleprivatemessages:model User Message

Now add the following entry to the model which will have the messages


If you have used anything other than "Message", you will have to pass the correct class name along as :class_name.

That's it.

= Usage

Examples assume you're using Restful Authentication or AAA, with a user model of User and message model of Message.

== Creating / sending a message:

frank = User.findbylogin("frank") george = User.findbylogin("george")

message = message.subject = "Happy Festivus, son" message.body = "It's time for the Feats of Strength." message.sender = frank message.recipient = george

== Reading a message

message = Message.read_message(id, user)

Returns the message of the chosen id and ensures the passed user is either the sender or the recipient. If unread, it checks to see if the passed user is the recipient and if so marks the read_at timestamp.

You can also check if a message has been read with the following:


== Retrieving a user's received mail

newman = User.findbylogin("newman") newman.received_messages

The following will return Newman's number of unread messages:


Or the following for true or false on whether there are unread messages:


== Retrieving a user's sent mail

newman = User.findbylogin("newman") newman.sent_messages

== Custom finds

newman.sentmessages.find(:all, :conditions => ["readat < ?", 2.days.ago], :limit => 20, :order => "created_at ASC")

== Deleting a message

newman = User.findbylogin("newman") message = newman.receivedmessages.find(3) message.markdeleted(newman)

This will look at a message and mark it read by the sender or recipient, based on whichever Newman is. It now will no longer appear in Newman's messages.

kramer = User.findbylogin("kramer") message = kramer.sentmessages.find(3) message.markdeleted

Now that both sender and recipient have marked the message deleted, it gets destroyed. Should a message be sent to oneself, it will be deleted in one step due to the sender and recipient being the same.

= Scaffold

A generator is included to create a basic controller and set of views.

Run the simpleprivatemessages:scaffold generator with the same options as before:

rails generate simpleprivatemessages:scaffold User Message

The controller will be named with the pluralised version of the model name.

Then uncomment the entry at the top of the message model to establish the :to accessor.

You should now have working messaging.

= RSpec In spec/spec_helper.rb add

require 'simple-private-messages/matchers'


config.include Professionalnerd::SimplePrivateMessages::Shoulda::Matchers

In user model spec file:

it { should haveprivatemessages }

and message model spec file:

it { should beprivatemessage }

= Tests

Unit tests are provided for the model extensions but not for the generated scaffold. Running these requires sqlite3.

=== Credits

Testing functionality for creating dedicated models / loading of a custom schema taken from actsastaggableonsteroids.

Thank you to nerdinand for the Rails 3 upgrade.

=== License

Copyright (c) 2007 Jon Gilbraith released under the MIT license

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.