Dynamic notification system for rails 3.
Add this line to your application's Gemfile:
gem 'megaphone'
And then execute:
$ bundle
Or install it yourself as:
$ gem install megaphone
Now, you have to generate the files megaphone needs to work
$ rails generate megaphone:install
After that, you justa have to add the following line to the model you want to receives messages
include Megaphone::Notifiable
Example:
class User
include Megaphone::Notifiable
# your code here
end
And then, User has many messages, use it like any other has_many relationship. Example:
User.last.messages.first
# => nil
User.last.messages.create! title: 'A Title', text: 'A text'
# => true
User.last.messages.first
# => #<Megaphone::Message>
Also, some basic helper methods were added to the User model
User.last.has_unread_messages?
# => true
User.last.unread_messages_count
# => 4
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request