与Faye的消息:ReferenceError:未定义Faye(Messaging with Faye : ReferenceError: Faye is not defined)
我在我的Rails应用程序中使用Faye websockets,就像Railcasts#260一样。一切都很好,但现在我得到的错误就像
ReferenceError:未定义Faye
这里
$(function() { var faye = new Faye.Client('http://localhost:9292/faye'); faye.subscribe("/games/messages/new", function(data) { eval(data) }); });
我开始了我的faye:
rackup faye.ru -s thin -E production
faye.ru
require 'faye' Faye::WebSocket.load_adapter('thin') faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45) run faye_server
我不知道发生了什么,我唯一改变的是安装rails-unicorn gem并默认启动它。
更新: http:// localhost:9292 /说:
当然你不是在寻找/ faye?
如果我添加/ faye -
错误的请求。
如果我添加/faye.js -
fs的js剧本
更新:对于现在它只是工作,不知道为什么,但它是。 谢谢你们。
I am using Faye websockets in my Rails application, just like Railcasts # 260. All was fine, but now I am getting error like
ReferenceError: Faye is not defined
here
$(function() { var faye = new Faye.Client('http://localhost:9292/faye'); faye.subscribe("/games/messages/new", function(data) { eval(data) }); });
I started my faye like:
rackup faye.ru -s thin -E production
faye.ru
require 'faye' Faye::WebSocket.load_adapter('thin') faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45) run faye_server
I don't know what's going on, the only thing I changed was install rails-unicorn gem and default booting from it.
UPDATE: http://localhost:9292/ says:
Sure you're not looking for /faye ?
And if I add /faye -
Bad request.
And if I add /faye.js -
js script of Faye
UPDATED: For a now it just works, don't know why, but it is. Thank you, all.
原文:https://stackoverflow.com/questions/28010609
最满意答案
从测试执行流程 (重点添加):
对于每个类,测试从运行类安装方法开始。 对于每个测试方法, 分配一个新的类实例并执行其实例设置方法。 之后它运行测试方法,然后运行实例拆解方法。 该序列重复了该类中的所有测试方法。 在运行了类中的最后一个测试方法后,Xcode执行类拆解方法并继续下一个类。 重复此序列,直到所有测试类中的所有测试方法都已运行。
在您的情况下,
test_B_fooIsNotNil()
在新实例上执行,其foo
属性为nil
。可以将常用设置代码放入
setUp()
类方法或setUp()
实例方法,请参阅了解测试方法的设置和拆解From Flow of Test Execution (emphasis added):
For each class, testing starts by running the class setup method. For each test method, a new instance of the class is allocated and its instance setup method executed. After that it runs the test method, and after that the instance teardown method. This sequence repeats for all the test methods in the class. After the last test method teardown in the class has been run, Xcode executes the class teardown method and moves on to the next class. This sequence repeats until all the test methods in all test classes have been run.
In your case,
test_B_fooIsNotNil()
is executed on a fresh instance, for which thefoo
property isnil
.Common setup code can be put into the
setUp()
class method orsetUp()
instance method, see Understanding Setup and Teardown for Test Methods
相关问答
更多-
类的可选实例(Optional instance of a class)[2022-12-20]
如果我理解你的问题,问题是你在if范围内创建了类的实例。 稍后你试着调用对象thomas的方法eatfood但是当前范围内不存在该对象。 也许你想这样做...... if (outputtype2) { cats thomas(outputtype1); thomas.eatfood(whiskers); } 或者使用指针...... Cats* thomas = NULL; if (outputtype2) { thomas = new Cats(outputtype1); } if ( ... -
实例变量:self vs @(Instance variable: self vs @)[2023-10-19]
写@age直接访问实例变量@age 。 写self.age告诉对象发送自己的消息age ,通常返回实例变量@age - 但是可以根据在一个给定的子类中如何实现age方法来做任何其他的事情。 例如,您可能有一个MiddleAgedSocialite类,总是报告其年龄比实际年龄小10岁。 或者更实际上,PersistentPerson类可能会从持久存储器中懒惰地读取该数据,并以哈希方式缓存其所有持久数据。 Writing @age directly accesses the instance variable ... -
从测试执行流程 (重点添加): 对于每个类,测试从运行类安装方法开始。 对于每个测试方法, 分配一个新的类实例并执行其实例设置方法。 之后它运行测试方法,然后运行实例拆解方法。 该序列重复了该类中的所有测试方法。 在运行了类中的最后一个测试方法后,Xcode执行类拆解方法并继续下一个类。 重复此序列,直到所有测试类中的所有测试方法都已运行。 在您的情况下, test_B_fooIsNotNil()在新实例上执行,其foo属性为nil 。 可以将常用设置代码放入setUp()类方法或setUp()实例方法,请 ...
-
可选变量匹配?(Optional variable match?)[2021-12-29]
我如何使$ c3和$ c4是可选的,所以当没有任何东西可以匹配时,正则表达式不会失败? 除非你必须使用个体变量,否则考虑使用一个数组来保存你想要的字符: use strict; use warnings; my @a = ( "a b", "a b c", "a b c d" ); for my $line (@a) { my @chars = split ' ', $line; #my @chars = $line =~ /\S+/g; # Or use this regex to c ... -
您根本不必在头文件中声明它们。 实例变量和属性通常在实现文件的私有类别中添加: @interface MyClass () { BOOL _someVar; } @property NSString *someOtherVar; - (void)_aPrivateMethod:(id)something; @end @implementation MyClass ... @end You don't have to declare them in the header file at al ...
-
如何使用instance_variable_set正确设置实例变量?(How to properly set an instance variable with instance_variable_set?)[2022-04-05]
我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你正在使用它。 它本质上是元编程的工具,或者是绕过实例变量可见性的黑客。 也就是说,如果该变量没有setter,则无论如何都可以使用instance_variable_set进行设置。 如果你控制代码只是创建一个setter,那就好多了。 尝试查看绝大多数实例变量设置需求的访问器。 它们是一种惯用的方法,可以“免费”为实例变量设置getter和setter,而无需编写这些函数。 如果你确实需要instance_variabl ... -
根据错误,您的方法的返回类型是Response 。 但是, update(resourceID, data).map(updatedResource -> Response.status(Response.Status.OK).entity(updatedResource).build())返回一个Optional ,因此您必须将返回类型更改为Optional
。 所以方法看起来像这样: public Optional yourMethod (...) { ... -
nil是一个可选类型,究竟背后是什么?(nil in an optional type, what exactly is behind it? what it looks like in the memory?)[2023-12-19]
有了这个 var john: Person? Stack顶部添加了一个内存插槽。 此插槽的类型是Person类型的Optional值 Optional在这个内存位置,我们找到了Optional.none值。 在这之后 john = Person(name: "Mr Robot") 一些内存被分配到Heap 。 然后按照Person initializer的逻辑写入该内存。 然后让我们回到堆栈。 这里Optional.none替换为值Optional.some , Person对象的地 ... -
是NSMutableArray实例,SWIFT默认是可选的吗?(Is NSMutableArray instance, optional by default in SWIFT?)[2022-04-06]
你的NSMutableArray没有问题。 var arr = NSMutableArray() 创建一个非可选的数组实例。 到目前为止,这么好......表达 NSMutableArray(contentsOfFile: plistfinalpath) 可以返回nil,因此返回可选值。 在这里,您尝试创建另一个NSMutableArray实例,并将结果分配给var arr。 包含指定aPath的文件内容的可变数组。 如果无法打开文件或者无法将文件内容解析为可变数组,则返回nil。 对你来说,最好的方法 ... -
可选变量内的变量(Variable inside optional variable)[2022-05-13]
从文档( https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/BasicOperators.html ) 如果a包含值,则nil-coalescing运算符(a ?? b)展开可选a;如果a为n,则返回默认值b。 表达式a始终是可选类型。 表达式b必须与存储在a中的类型匹配。 在这种情况下,如果row.section为nil,则整个表达式(row.secti ...