小编Bry*_*anH的帖子

使用Rails的多对多关系时,"NameError:uninitialized constant"

我有以下型号:

class Person < ActiveRecord::Base
  has_many :accounts, :through => :account_holders 
  has_many :account_holders
end

class AccountHolder < ActiveRecord::Base
  belongs_to :account
  belongs_to :people
end

class Account < ActiveRecord::Base
  has_many :people, :through => :account_holders 
  has_many :account_holders
end
Run Code Online (Sandbox Code Playgroud)

但是,在使用这种关系时我遇到了问题.Account.first.account_holders工作正常,但Account.first.people返回:

NameError: uninitialized constant Account::People
    from /Users/neil/workspace/xx/vendor/rails/activesupport/lib/active_support/dependencies.rb:105:in `const_missing'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/base.rb:2204:in `compute_type'
    from /Users/neil/workspace/xx/vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/base.rb:2200:in `compute_type'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/reflection.rb:156:in `send'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/reflection.rb:156:in `klass'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/associations/has_many_through_association.rb:73:in `find_target'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:353:in `load_target'
    from /Users/neil/workspace/xx/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:139:in `inspect'
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

activerecord many-to-many ruby-on-rails

1
推荐指数
1
解决办法
2514
查看次数

谷歌找到了我的备份网站.我该怎么办呢?

几天前,我们用更新版本替换了我们的网站.原始网站的内容已迁移到http://backup.example.com.搜索引擎不了解旧网站,我不希望他们知道.

在我们更新网站的过程中,Google抓取了旧版本.

现在,当使用Google搜索我们的网站时,我们会获得新旧网站的结果(例如,http: //www.example.comhttp://backup.example.com).

这是我的问题:

  1. 我可以使用新内容更新备份网站内容吗?然后我们可以摆脱所有旧内容.我担心的是,由于内容重复,Google会降低我们的网页排名.
  2. 如果我阻止访问旧网站,那么从Google的搜索结果中清除信息需要多长时间?
  3. 我可以使用google disallow阻止Google访问旧网站.

seo

1
推荐指数
1
解决办法
433
查看次数

计数视图控制器

我似乎无法获得视图控制器堆栈中的视图控制器数量.

NSUInteger *viewControllerCount = self.navigationController.viewControllers.count;
Run Code Online (Sandbox Code Playgroud)

我可以遍历视图控制器和NSLog内部的对象,但我不能做一个简单的计数.如果我尝试访问此指针,则崩溃...没有日志,没有错误消息,nada.请帮忙!

iphone view controllers uiviewcontroller ios

1
推荐指数
1
解决办法
1816
查看次数

在void函数中使用未声明的标识符'sender'

我做一个自定义SegueStoryboard,我有一个包含此代码的按钮:

 [self performSegueWithIdentifier:@"line3" sender:sender];
Run Code Online (Sandbox Code Playgroud)

点击按钮就可以了.我遇到的问题是这个代码只能在一个不在void函数内部的按钮函数中运行.我试着点击按钮,效果很好.当我将其粘贴到void函数中时,它会给我一个抱怨发件人的错误.我尝试将其更改为无效,但没有任何反应.你能给我一些解决这个问题的见解吗?我正在检查a UserDefault并且它与我正在寻找的匹配然后我想要执行此代码:[self performSegueWithIdentifier:@"line3" sender:sender];

-(IBAction)LoginAttemp:(id)sender{
    [self performSegueWithIdentifier:@"line3" sender:sender];
}



-(void) LoginFailed{
    [self performSegueWithIdentifier:@"line3" sender:sender];
}
Run Code Online (Sandbox Code Playgroud)

错误我得到:

使用未声明的标识符'sender'

任何见解?

objective-c ios segue

1
推荐指数
1
解决办法
4774
查看次数

我可以使用汇编语言创建什么类型的应用程序/项目?

我在大学的第三个学期.我简直不知道怎么写汇编语言什么:我只是用MASM,写movadd eax,var1指令排序.

我们可以用汇编语言创建类似于我们在C/C++中可以做的程序吗?

您能否推荐使用Assembly构建的任何示例项目?

assembly

1
推荐指数
1
解决办法
1万
查看次数

Genymotion中谷歌地图报告的GPS位置不正确

我正在使用Genymotion模拟器测试我需要GPS位置的Android应用程序.

当我启动Google地图应用程序时,它会给我一个错误的位置.有人对此有任何想法吗?

gps android google-maps genymotion

1
推荐指数
1
解决办法
1万
查看次数

神话人月传播路径真的是n ^ 2吗?

它不会更接近:

n * (n - 1) / 2

以上公式是这个中学数学团队问题的答案:

"你在一个房间里有n个人,他们都和其他人握手.发生了多少次握手?"

这也不适用于在软件项目中进行通信的人数吗?

放弃

我还没有读过这本书,但我已经看过n^2其他地方引用的公式.

algorithm sdlc communication

0
推荐指数
3
解决办法
1268
查看次数

错误:未定义[function]

我得到一个未定义的函数错误,对于我的生活,我无法弄清楚.这个脚本有什么问题?

var numnames=0;
var names=new Array();
function SortNames(){
thename=document.theform.newname.value;
numnames++;
names.sort();
document.theform.sorted.value=names.join("\n");
}
Run Code Online (Sandbox Code Playgroud)

我在这里调用代码:

<html>
<head></head>
<body>

<script type="text/javscript" language="javascript" src="sort.js">
</script>
<h1>Sorting Array</h1>
<p>Enter two or more names in the field below, and the sorted list of names will appear in the text area<p>
<form name=theform>
Name:
<input type=text name=newname size=20>
<input type=button name=addname value=Add onclick="SortNames();">
<br/>
<h2>Sorted Names</h2>
<textarea cols=60 rows=10 name=sorted>
The sorted names will appear here
</textarea>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我得到的错误是SortNames is not defined.

javascript undefined

0
推荐指数
1
解决办法
744
查看次数

未捕获的ReferenceError:没有定义Lawnchair

我正试图让基本的草坪椅示例工作.

代码:

<script type="text/javscript" src="http://westcoastlogic.com/lawnchair/src/lawnchair.js"></script>

<script type="text/javascript">
    var people = new Lawnchair('people');
</script>
Run Code Online (Sandbox Code Playgroud)

出现以下错误(在FF和Chrome控制台中):

未捕获的ReferenceError:没有定义Lawnchair

我究竟做错了什么?

javascript local-storage lawnchair

0
推荐指数
1
解决办法
3163
查看次数

如何使用zxing在Android中编写条形码扫描器

我想在我的Android应用程序中集成条形码扫描程序.

我试图添加zxing库,但我的所有应用程序都是在没有扫描的情况下显示摄像机视图.

http://code.google.com/p/zxing/

有没有一种简单的方法来集成条形码扫描功能?

camera android barcode-scanner zxing

0
推荐指数
1
解决办法
2354
查看次数