Gravtastic saves a ton of headaches when wanting a gravatar.
In 4 lines of code (seriously 4) I had a gravatar up and running on my app.
Here’s how.
Getting Started
Keep in mind, gravtastic relies on Devise to work. So all of the instructions are
to be used after Devise is setup.
Go ahead and add the gem gravtastic to your Gemfile.
1
|
|
As always, make sure to bundle after installing a gem.
1
|
|
Implementation
Now we need to make sure our model uses gravtastic. Your file may be different depending on what you named your devise model. I’m going to name mine User and generate the code on that premise.
1 2 3 4 5 |
|
With that gravtastic has been able to hook into your devise model. Hooray!
The last job is rendering the gravatar to the view.
I’m using Haml, so the html syntax may be weird. If you’re using Erb, just
replace the = with <%= and end the line with %>
1
|
|
That’s it!
Now a gravatar should be rendering on your page.
If you want to adjust the size you can pass a size option on gravtastic in the model.
The specifics of different options to use can be found on
the Gravtastic Github Page