public
Description: has_messages is a plugin that provides messages functionality in your rails application.
Homepage:
Clone URL: git://github.com/bryansray/has_messages.git
name age message
file .DS_Store Wed Jun 18 15:10:14 -0700 2008 Initial commit [bryansray]
file CHANGELOG Wed Jun 18 15:10:14 -0700 2008 Initial commit [bryansray]
file MIT-LICENSE Wed Jun 18 15:10:14 -0700 2008 Initial commit [bryansray]
file README.textile Wed Jun 18 15:19:28 -0700 2008 Updated the README to support github Textile an... [bryansray]
file Rakefile Wed Jun 18 15:10:14 -0700 2008 Initial commit [bryansray]
directory app/ Thu Jun 19 10:55:15 -0700 2008 Just syntax alignment [bryansray]
directory db/ Wed Jun 18 15:10:14 -0700 2008 Initial commit [bryansray]
file init.rb Wed Jun 18 15:10:14 -0700 2008 Initial commit [bryansray]
directory lib/ Wed Jun 18 15:10:14 -0700 2008 Initial commit [bryansray]
directory test/ Wed Jun 18 15:10:14 -0700 2008 Initial commit [bryansray]
README.textile

Information

This is a ‘fork’ of the code base from http://svn.pluginaweek.org/trunk/has_messages. I’ve replaced the state_machine plugin with acts_as_state_machine and plugins_plus with engines. Eventually I’ll get around to removing the engines dependency at all, because I don’t think it is necessary, but for now this will work.

has_messages

has_messages demonstrates a reference implementation for sending messages between users.

Resources

Wiki

  • http://wiki.pluginaweek.org/Has_messages

API

  • http://api.pluginaweek.org/has_messages

Development

  • http://dev.pluginaweek.org/browser/trunk/has_messages

Source

  • http://svn.pluginaweek.org/trunk/has_messages

Description

Messaging between users is fairly common in web applications, especially those
that support social networking. Messaging doesn’t necessarily need to be
between users, but can also act as a way for the web application to send notices
and other notifications to users.

Designing and building a framework that supports this can be complex and takes
away from the business focus. This plugin can help ease that process by demonstrating
a complete implementation of these features.

Usage

Adding message support

class User < ActiveRecord::Base has_messages end

This will build the following associations:

  • messages
  • unsent_messages
  • sent_messages
  • received_messages

If you have more specified needs, you can create the same associations manually
that has_messages builds. See PluginAWeek::HasMessages::MacroMethods#has_messages
for more information about the asssociations that are generated from this macro.

Creating new messages

message = user.messages.build message.to user1, user2 message.subject = ‘Hey!’ message.body = ‘Does anyone want to go out tonight?’ message.deliver!

Replying to messages

reply = message.reply_to_all reply.body = “I’d love to go out!” reply.deliver!

Forwarding messages

forward = message.forward forward.body = ‘Interested?’ forward.deliver!

Processing messages asynchronously

In addition to delivering messages immediately, you can also queue messages so
that an external application processes and delivers them. This is especially
useful for messages that need to be sent outside of the confines of the application.

To queue messages for external processing, you can use the queue! event,
rather than deliver!. This will indicate to any external processes that
the message is ready to be sent.

To process queued emails, you need an external cron job that checks and sends
them like so:

Message.with_state(‘queued’).each do |message| message.deliver! end

Testing

Before you can run any tests, the following gem must be installed:

  • plugin_test_helper[http://wiki.pluginaweek.org/Plugin_test_helper]

To run against a specific version of Rails:

rake test RAILS_FRAMEWORK_ROOT=/path/to/rails

Dependencies