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
v0.3 will be the last version.
Add this line to your application's Gemfile:
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
# 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,
Emojimmy.emoji_to_token("Hello! 😁") # => "Hello! :grin:" Emojimmy.token_to_emoji("Hello! :grin:") # => "Hello! 😁"
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.