ruby-on-rails rails 4.2在哪里编写Bullet的白名单代码

khbbv19g  于 2023-05-30  发布在  Ruby
关注(0)|答案(2)|浏览(111)

我是Rails的新手,使用Bullet gem来检测n+1个查询。有一种方法可以编写白名单来忽略一些特殊关联上的n+1个查询警告。但是我不知道我应该在哪里写这部分代码。在rails配置文件中似乎写得不对。

umuewwlo

umuewwlo1#

config/environments/development.rb中,您将编写bullet gem的配置。
所以要加入白名单,你需要编写如下代码。

config.after_initialize do
  Bullet.add_whitelist :type => :n_plus_one_query, :class_name => "Post", :association => :comments
  Bullet.add_whitelist :type => :unused_eager_loading, :class_name => "Post", :association => :comments
  Bullet.add_whitelist :type => :counter_cache, :class_name => "Country", :association => :cities
end
vjrehmav

vjrehmav2#

仅供参考-文档已更新。它不再是add_whitelist,而是add_safelist。

config.after_initialize do
  Bullet.add_safelist :type => :n_plus_one_query, :class_name => "Post", :association => :comments
  Bullet.add_safelist :type => :unused_eager_loading, :class_name => "Post", :association => :comments
  Bullet.add_safelist :type => :counter_cache, :class_name => "Country", :association => :cities
end

相关问题