我在 Ruby on Rails 5.1.4 版上使用 gem Merit 3.0.1 制作成就系统。但是当我尝试在 POST 方法或 Rails 控制台上创建用户时,问题就来了。问题来了ActiveRecord::RecordInvalid: Validation failed: Sash must exist
。我已经关注了这个链接https://github.com/merit-gem/merit/issues/265并且它说我必须使窗扇成为可选然后由另一个 github 用户拉出自定义的优点宝石,它进展顺利,直到当我看到每个用户的nil
sash_id 是 ,如果 sash_id 是nil
,则意味着徽章无法与用户建立关系。问题是什么?我已经尝试了 github 中的每一步,但仍然没有任何线索。每次注册用户时我是否都手动创建了 sash_id?谢谢你。
这是我的用户模型
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