ruby-on-railsmerit-gem

How to display the creation date of a badge earning with merit gem


I'm trying to find a way to display in a View the badge & the "granted_at" record. It would render (in the view) :

 <% @profil.badges.each do |badge| %>                                                                       
   <%= image_tag (badge.custom_fields[:image]), badge.granted_at %>
 <% end %>

Should I enable the MeritObserver to get this on the view ? Or there is a simpler solution?

(I'm on Rails 5)

EDIT

Thanks to TuteC, we have an answer :

<% @profil.sash.badges_sashes.each do |badge_sash| %>
    <%= image_tag (badge_sash.badge.custom_fields[:image]) %><%= badge_sash.created_at %>
<% end %>

Solution

  • You've got to go through sash and badges_sashes relations:

     <% @profil.sash.badges_sashes.each do |badge_sash| %>
       <%= image_tag(badge_sash.badge.custom_fields[:image]), badge_sash.created_at %>
     <% end %>
    

    You can read about merit internals in https://github.com/merit-gem/merit/wiki/General-merit-workflow.