I'm making achievement system using gem merit 3.0.1 on Ruby on Rails version 5.1.4. But the problem comes when I'm trying to create User either on POST method or on rails console.
The problem goes ActiveRecord::RecordInvalid: Validation failed: Sash must exist. I have followed this link https://github.com/merit-gem/merit/issues/265 and it says that I have to make the sash optional then pulling the custom merit gem by another github user, and it goes well, until when I see that sash_id of each user is nil, if sash_id is nil, it means the badges cannot make relationship with the user.
What is the problem? I have tried every step that inside the github and stil no clue. Do I have manually create the sash_id each time User is registered? Thank you.
This is my user model
class User < ApplicationRecord
include Merit
has_merit
has_many :activities, dependent: :destroy
has_many :locations, as: :locationable
has_many :active_relationships, class_name: "Relationship", foreign_key: "follower_id", dependent: :destroy
has_many :following, through: :active_relationships, source: :followed
has_many :passive_relationships, class_name: "Relationship", foreign_key: "followed_id", dependent: :destroy
has_many :followers, through: :passive_relationships, source: :follower
def follow(other_user)
following << other_user
end
def unfollow(other_user)
following.delete(other_user)
end
def following?(other_user)
following.include?(other_user)
end
class << self
def find_for_verfied_token_response(auth,provider,access_token)
user = find_or_create_by(uid: auth['id'])
if provider == "facebook"
user.profile_picture = auth['picture']['data']['url']
elsif provider == "google_oauth2"
user.profile_picture = auth['picture']
end
user.email = auth['email']
user.full_name = auth['name']
user.gender = auth['gender']
user.provider = provider
user.access_token = access_token
puts(user)
user.save!
user
end
def save_api_key(email,uid,api_key)
user = User.where(email: email, id: uid).first
user.api_key = api_key
user.save!
user
end
end
end
I just ran into the same problem. please use this branch
and i think it'll fix it. BTW what version of rails are you using?