So I just installed the merit gem and have been using it to implement badges within my application. I define the badge inside the config/initializers/merit.rb
file as so:
badge_id = 0
[{
id: (badge_id = badge_id + 1),
name: 'badge-one',
custom_fields: { test_id: 'sample_id' }
}].each do |attrs|
Merit::Badge.create! attrs
end
This badge is rewarded to the user when the user is created. The user is created within the user_controller.rb
within the create
method:
grant_on 'user#create', badge_id: 1, badge: 'badge-one', to: @user
For some reason when a new user is created the the badge is never rewarded. When I type Merit::Badge.find(1)
I see that the badge is indeed defined. However, when I type User.first.badges
into my console it returns an empty array. Why isn't the badge being rewarded to the user when they sign up? Please let me know if you need any additional information to help out with solving this issue.
Edit To Provide More Information
Here is what I get when I run in Merit::Badge.find(1).inspect
inside the console:
#<Merit::Badge id: 1, name: \"badge-one\", level: nil, description: nil, custom_fields: {:test_id=>\"sample_id\"}>