Mezu is a Rails 3 Engine to manage system messages globally, or for a specific object.
It's a piece of cake!
gem "mezu"
$ bundle install # Of course, you can execute `gem install mezu`
rails generate mezu:install
rake db:migrate
This step create some files on your Rails project...
db/migrate/yyyymmddhhmmss_create_mezu_messages.rb
db/migrate/yyyymmddhhmmss_create_mezu_readings.rb
config/initializers/mezu.rb
public/mezu/mezu.css
class CreateMezuMessages < ActiveRecord::Migration
def self.up
create_table :mezu_messages do |t|
t.string :title, :null => false
t.string :level, :limit => 10, :null => false
t.text :body
t.string :locale, :null => false
t.datetime :expires_at
t.references :messageable, :polymorphic => true, :null => true
t.timestamps
end
add_index :mezu_messages, [:messageable_type, :messageable_id]
end
def self.down
drop_table :mezu_messages
end
end
class CreateMezuReadings < ActiveRecord::Migration
def self.up
create_table :mezu_readings do |t|
t.references :message, :null => false
t.references :reader, :polymorphic => true, :null => false
t.timestamps
end
add_index :mezu_readings, :message_id
end
def self.down
drop_table :mezu_readings
end
end
This engine adds on your app the path /mezu
, to CRUD your mezu system messages
To protect mezu system messages access on your CRUD, go to config/initializers/mezu.rb
file and implement your powerful authentication protection.
messages = Mezu::Message.list(:user => current_user.id, :group => current_user.group_ids)
message = Mezu::Message.first
message.read_by!(user)
Mezu::Message.list(:user => current_user.id, :group => current_user.group_ids).unread_by(current_user)
If you're handling more than one locale, you can configure which locales you can associate messages with. Just go to config/initializers/mezu.rb
and set the available locales:
Mezu.configure do
config.available_locales = [:en, :"pt-BR"]
end
By default, these will return the I18n.available_locales
list.
You can then filter the message with by_locale
scope:
Mezu::Message.by_locale(I18n.locale)
See on commits!