MessageTrain

Rails 4 Private Messaging Gem

Installation

First, install the gem:

gem 'message_train'

Then, run the install generator:

rails g message_train:install

And then run rake db:migrate.

Next, add to your models, each of which will need some kind of display name column and some kind of slug (could be the same). See below for the options for this mixin:

in /app/models/user.rb

message_train

OR to set the name and slug columns:

message_train slug_column: :short_name, name_column: :display_name

Add to your application.css.scss:

@import "message_train";

And in your application.js:

//= require message_train

In your layout, supposing you use haml:

#alert_area
  = alert_flash_messages

Required helper methods

If you don't use devise with its current_user method, you will need to configure MessageTrain to use whatever method you use:

MessageTrain.configure do |config|
  config.current_user_method = :current_subscriber
end

Mixin options

The message_train mixin takes the following options:

[:only] A symbol or array of symbols to be the only relationships used, which can include: [:sender, :recipient] [:except] A symbol or array of symbols not to create relationships for, which can include: [:sender, :recipient] [:valid_senders] A method name to call for a list of valid senders for this model [:name_column] The column by which to name and find this model. default: :name [:slug_column] The column with the short, typeable form of the name. default: :slug

Smaller address book

By default, the address book will contain all objects of the current_user_method object's model type. To change this behavior, define an address book method on your user model, something like this:

def address_book
    friends
end

And in your initializer:

self.address_book_method = :address_book

View Helpers

Boxes

[boxes_dropdown_list] Bootstrap navigation dropdown list of boxes. (Be sure to check that user is signed in before calling, or you'll get errors.) [boxes_widget] Bootstrap widget with list of boxes [box_nav_item(box)] Bootstrap list item for one box [box_list_item(box)] Bootstrap list item for one box [box_participant_name(participant)] Name of the participant, according to the method specified in your configuration or model. [box_participant_slug(participant)] Slug of the participant, according to the method specified in your configuration or model.

Conversations

[conversation_senders(conversation)] List of senders for a given conversation [conversation_class(box, conversation)] CSS class to put on a given conversation when in a certain box [conversation_trashed_toggle(conversation)] Link to toggle trashed status of a conversation [conversation_read_toggle(conversation)] Link to toggle read status of a conversation [conversation_ignored_toggle(conversation)] Link to toggle ignored status of a conversation [conversation_deleted_toggle(conversation)] Link to toggle deleted status of a conversation [conversation_toggle(conversation, icon, mark_to_set, method, title, options = {})] Link to toggle some status of a conversation

Messages

[message_class(box, message)] CSS class to put on a given message when in a certain box [message_trashed_toggle(message)] Link to toggle trashed status of a message [message_read_toggle(message)] Link to toggle read status of a message [message_deleted_toggle(message)] Link to toggle ignored status of a message [message_toggle(message, icon, mark_to_set, title, options = {})] Link to toggle some status of a message [message_recipients(message)] Recipients for a given message

Contributing to MessageTrain

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright (c) 2015 Gem Vein. See LICENSE.txt for further details.