我有一位客户去了有经理的商店。 Customer和Manager都来自People模型,只有不同的角色。
从客户那里获得经理的最佳方式是什么?
现在我的解决方案很慢:
width:(100% - 470px)
person.rb:
shop_manager = customer.shop.people.select{|p| p.has_role?(:manager)}.first
shop.rb:
belongs_to :shop
使用rolify gem分配角色。
答案 0 :(得分:3)
喜欢这个吗?
shop_manager = customer.shop.people.with_role(:manger).first