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
OR to set the name and slug columns:
slug_column: :short_name, name_column: :display_name
Add to your application.css.scss:
@import "message_train";
And in your application.js:
//= require
In your layout, supposing you use haml:
#alert_area
=
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:
name_column: :current_subscriber
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
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
Copyright (c) 2015 Gem Vein. See LICENSE.txt for further details.