我按照这里的说明,通过安装composite_primary_keys gem
sudo gem install composite_primary_keys
Run Code Online (Sandbox Code Playgroud)
这工作得很好.现在,当我将以下内容添加到我的模型中时
set_primary_keys :user_id, :group_id
Run Code Online (Sandbox Code Playgroud)
我明白了
undefined method `set_primary_keys' for #<Class:0x1043bfe20>
Run Code Online (Sandbox Code Playgroud)
此外,如此处所述,在迁移中使用多个主键无效.
任何想法为什么这可能不起作用以及如何使其工作?
注:我没有想为什么我不应该使用组合键来讲话-我已经下定了决心,只是希望得到这个工作.谢谢!
我倾向于使用来自Subversion的Mercurial,我想维护一个像Subversion一样的集中式工作流程.这就是我的想法:
stable (clone on server)
default (branch)
development (clone on server)
default (branch)
bugs (branch)
developer1 (clone on local machine)
developer2 (clone on local machine)
developer3 (clone on local machine)
feature1 (branch)
developer3 (clone on local machine)
feature2 (branch)
developer1 (clone on local machine)
developer2 (clone on local machine)
Run Code Online (Sandbox Code Playgroud)
就分支机构与克隆而言,这个工作流程是否有意义?我有事情吗?
此外,'稳定'克隆是释放.将'默认'分支作为发布以及所有其他分支最终合并到什么内容是否有意义?
假设我有以下XML:
<data>
<authors>
<author>
<name>
<first_name>Stephen</first_name>
<last_name>Baxter</last_name>
</name>
</author>
<author>
<name>
<first_name>Joe</first_name>
<last_name>Haldeman</last_name>
</name>
<author>
</authors>
<books>
<book>
<name>The Time Ships</name>
</book>
<book>
<name>The Forever War</name>
<book>
</books>
</data>
Run Code Online (Sandbox Code Playgroud)
在我的DTD中,我如何解释"name"元素用于作者和书籍的事实,并且可以有不同的子元素 - 像这样?
<!ELEMENT name (#PCDATA|first_name,last_name)>
Run Code Online (Sandbox Code Playgroud) 目前,我在我的JavaScript库中实现了继承,如下所示:
parent = function() { };
parent.prototype.hello = function() { alert('parent'); };
child = function() { };
child.prototype = parent.prototype;
Run Code Online (Sandbox Code Playgroud)
但是,我注意到当我覆盖子类"class"原型中的函数时,它也会不合理地覆盖父类的原型:
child.prototype.hello = function() { alert('child'); }
(new parent()).hello(); // alerts "child" --> undesirable
(new child()).hello(); // alerts "child" --> desirable
Run Code Online (Sandbox Code Playgroud)
如果我从孩子的原型中删除了一些东西
delete child.prototype.hello;
Run Code Online (Sandbox Code Playgroud)
然后父母的原型受到不利影响.也许吧
child.prototype = parent.prototype;
Run Code Online (Sandbox Code Playgroud)
是不是实现继承的最佳方式?而不是让孩子"类"引用父原型,也许将父原型复制到子原型更有意义?
_.extend(child.prototype, parent.prototype);
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,每个路由都要求在呈现之前从我的API检索帐户数据.为此,我使用ngRoute执行以下操作:
$rootScope.$on('$routeChangeStart', function(event, next, current) {
next.$$route.resolve = next.$$route.resolve || {};
next.$$route.resolve.authorizationCheck = function() {
return deferredAccountData.promise;
};
});
Run Code Online (Sandbox Code Playgroud)
因此,在每个路由之前authorizationCheck,必须解决返回promise的resolve.这非常有效.
我现在转而使用UI路由器,我需要保留此功能.有什么选择来实现这个目标?
我能想到的一个选择是使用嵌套状态并使所有路由继承从父状态解析.虽然如果可能的话我宁愿不窝.还有其他选择吗?
使用SVN,我有以下设置:
/tags/
/trunk/
/branches/
/branches/my_feature
/branches/my_other_feature
Run Code Online (Sandbox Code Playgroud)
我想保持所有分支与主线中继同步,所以我定期为trunk的分支运行svn merge.
但是,我还希望保持所有分支彼此同步,以避免冲突,因为任何给定分支的生命周期可能是几个月或更长时间.如果我有十几个分支,我会有一个与SVN讨厌的网格,这将是不切实际的.
我的问题是,使用Git而不是SVN帮助保持分支彼此同步和中继?
我有以下平树:
id name parent_id is_directory
===========================================================
50 app 0 1
31 controllers 50 1
11 application_controller.rb 31 0
46 models 50 1
12 test_controller.rb 31 0
31 test.rb 46 0
Run Code Online (Sandbox Code Playgroud)
我试图找出一个算法,将其纳入以下树结构:
[{
id: 50,
name: app,
is_directory: true
children: [{
id: 31,
name: controllers,
is_directory: true,
children: [{
id: 11,
name: application_controller.rb
is_directory: false
},{
id: 12,
name: test_controller.rb,
is_directory: false
}],
},{
id: 46,
name: models,
is_directory: true,
children: [{
id: 31,
name: test.rb,
is_directory: false
}]
}]
}] …Run Code Online (Sandbox Code Playgroud) 我在Mac OS X上,当我运行sudo bundle install时,它在目标机器上安装了几个gem:
Installing ptools (1.2.1)
Using thor (0.14.6)
Using railties (3.0.5)
Using rails (3.0.5)
Installing rails_config (0.2.4)
Using shoulda (2.11.3)
Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed.
imac-cf:gnymbus apple$ rails console
Could not find rake-0.9.2 in any of the sources
imac-cf:gnymbus apple$ sudo gem install rake-0.9.2
ERROR: Could not find a valid gem 'rake-0.9.2' (>= 0) in any repository
imac-cf:gnymbus apple$ sudo gem install rake -v=0.9.2
Successfully installed …Run Code Online (Sandbox Code Playgroud) 获取模型数据时"成功"回调的目的与绑定到"更改"事件的方法的目的是什么?
"成功"回调
this.model.fetch({
url: '...'.
success: function(response) {
...
}
});
Run Code Online (Sandbox Code Playgroud)
与模型"改变"绑定
this.model.bind("change", this.attributesChanged);
Run Code Online (Sandbox Code Playgroud) 任何人都可以解释为什么$ watch()为我的范围触发,即使newValue == oldValue在这里?
scope.$watch('element', function(newValue, oldValue) {
if (newValue == oldValue) {
console.log(newValue == oldValue);
return;
}
}, true);
Run Code Online (Sandbox Code Playgroud)
输出"true",newValue和oldValue都是具有相同值的对象:
{"formID":"536826128a1c00617d3e4c5f","elementType":"TextFieldElement","required":false,"note":"","label":"","fieldName":"","_id":"5368261b8a1c00617d3e4c60","__v":0,"$$hashKey":"01B"}
{"formID":"536826128a1c00617d3e4c5f","elementType":"TextFieldElement","required":false,"note":"","label":"","fieldName":"","_id":"5368261b8a1c00617d3e4c60","__v":0,"$$hashKey":"01B"}
Run Code Online (Sandbox Code Playgroud)
我从文档中了解到,使用angular.equals()将第三个参数的"true"传递给$ watch来比较对象的相等性.我还测试了angular.equals(),它也返回true.那么为什么$ watch()会被触发呢?
我正在使用AngularJS v1.2.16.
javascript ×3
angularjs ×2
rubygems ×2
backbone.js ×1
branch ×1
dtd ×1
dvcs ×1
git ×1
inheritance ×1
mercurial ×1
prototype ×1
ruby ×1
tree ×1
xml ×1