我正在使用Starburst gem来显示用户登录时的通知。可以选择限制用户
Starburst::Announcement.create(
:body => 'Upgrade to platinum and save 10% with coupon code XYZ!',
:limit_to_users =>
[
{
:field => "subscription",
:value => "gold"
}
]
)
有没有办法为这样的字段传递多个值:
{
:field => "subscription",
:value => ["gold","silver"]
}
由于
答案 0 :(得分:1)
目前Starburst并不支持'或'在查询中。您最好的选择是在您的用户类上创建一个方法并将其用于定位,这将获得相同的结果。
添加到User类:
class User < ActiveRecord::Base
def gold_or_silver
subscription == "gold" || subscription == "silver"
end
end
然后在config / initializers / starburst.rb中启用该方法(如果它尚不存在则创建它):
Starburst.configuration do |config|
config.user_instance_methods = ["gold_or_silver"] '
end
然后过滤消息:
Starburst::Announcement.create(
:body => 'Upgrade to platinum and save 10% with coupon code XYZ!',
:limit_to_users =>
[
{
:field => "silver_or_gold",
:value => true
}
]
)