Emojimmy makes it possible to store emoji characters in ActiveRecord datastores
that don’t support 4-Byte UTF-8 Unicode (utf8mb4
) encoding.
You probably should be using a database that supports utf8mb4
though (and not this gem), like PostgreSQL or MySQL (5.5+). We built this gem because stock Heroku machines cannot compile the mysql2
gem to use the utf8mb4
encoding (because they ship with an old version of libmysqlclient
).
v0.3
will be the last version.
Add this line to your application's Gemfile:
gem 'emojimmy'
You have to edit your models to specify which fields will be storing emoji characters:
# app/models/comment.rb
class Comment < ActiveRecord::Base
stores_emoji_characters :body
end
Your model will now be able to store emoji characters in its body
column.
# Create a comment with an emoji
@comment = Comment.create(body: "Hello! 😁")
# Our comment has been saved in the database
@comment.persisted? # => true
# Magic! Our body contains the emoji!
@comment.body # => "Hello! 😁"
# The real magic… how emoji are actually stored
@comment.read_attribute(:body) # => "Hello! :grin:"
If you only want to use Emojimmy’s conversion methods, you can use two methods, token_to_emoji
and emoji_to_token
:
Emojimmy.emoji_to_token("Hello! 😁")
# => "Hello! :grin:"
Emojimmy.token_to_emoji("Hello! :grin:")
# => "Hello! 😁"
Emojimmy
is © 2013-2015 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md
file.
Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.
We also love open-source software and we try to give back to the community as much as we can.