@comment.body.scan(/@(\w+)/).flatten.to_a.each do|username|
if @mentioned = User.where(:username => username).any?
#@mentioned value??
end
end
如何在真正的
时获得@ mentioned的值答案 0 :(得分:2)
您想通过用户名获取User
并检查是否有用户名吗?
@comment.body.scan(/@(\w+)/).flatten.to_a.each do|username|
@mentioned = User.find_by_username(username)
if !@mentioned.blank?
# @mentioned is a User model instance.
@mentioned.username == username # => true
end
end