我正在使用Ruby 2.2.1和Rails 4.2来构建应用程序.在我的一个观点中,我收到以下消息:
检测到N + 1查询Politician => [:account]添加到您的finder :: includes => [:account]
N + 1查询方法调用堆栈
app/models/user.rb:19:在`account'中
app/controllers/home_controller.rb:6:在'index'中
这是我在家控制器上的动作:
@account = current_user.account
@new_contacts = current_user.contacts.created_this_week.count
@new_collabs = current_user.collaborators.created_this_week.count
Run Code Online (Sandbox Code Playgroud)
以及用户模型的相关部分:
belongs_to :role, polymorphic: true, dependent: :destroy
delegate :account, to: :role
delegate :collaborators, to: :role
delegate :contacts, to: :role
Run Code Online (Sandbox Code Playgroud)
我已经尝试过以下方法:
@account = current_user.account.includes(:contacts, :collaborators)
Run Code Online (Sandbox Code Playgroud)
但我只得到错误:
undefined method `includes' for <Account:0x007fa7474e04a8>
Run Code Online (Sandbox Code Playgroud)
我做了一些研究,看起来似乎只包括关系的作品(事实并非如此).
子弹无所畏惧吗?我该怎么做才能停止成为N + 1查询?
谢谢!
我正在尝试使用 Octokit gem for ruby 从某个用户的组织中检索所有存储库。
我有这个客户端变量:
@client = Octokit::Client.new(access_token: TOKEN)
Run Code Online (Sandbox Code Playgroud)
当我使用它时:
@client.repos
Run Code Online (Sandbox Code Playgroud)
我能够检索用户的所有存储库(甚至来自组织的私有存储库)
但是有了这个
@client.repos(some_org_id)
Run Code Online (Sandbox Code Playgroud)
我只从 some_org_id 组织获得公共的。
我的 OAuth 令牌范围设置了以下权限:
repo, user, read:org
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?该API文件建立提到的回购隐私的默认值是all。
提前致谢
有没有办法在 Ace 编辑器上检测右键单击事件?
我一直在尝试添加这样的侦听器:
editor.session.addEventListener('contextmenu', function(e) {
e.preventDefault();
alert('success!');
return false;
}, false);
Run Code Online (Sandbox Code Playgroud)
和这个
editor.addEventListener('contextmenu', function(e) {
e.preventDefault();
alert('success!');
return false;
}, false);
Run Code Online (Sandbox Code Playgroud)
但没有成功。
ruby ×2
ace-editor ×1
activerecord ×1
contextmenu ×1
dom-events ×1
github ×1
github-api ×1
javascript ×1
octokit ×1
performance ×1