使用call和apply调用函数有什么区别?
var func = function() {
alert('hello!');
};
Run Code Online (Sandbox Code Playgroud)
func.apply(); VS func.call();
上述两种方法之间是否存在性能差异?当它最好使用call过apply,反之亦然?
我在我们的rails app中有一个测试挂起无法找出哪一个(因为它挂起并且没有得到失败报告).我发现这篇博客文章http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/,它添加了一个设置挂钩来打印测试名称,但是当我尝试做同样的事情它给了我一个错误说错误的设置参数数量(1表示0).任何帮助都将不胜感激.
我有一个简单的UIViewController和a UISearchBar,当视图加载时我想让搜索栏立即成为第一个响应者,以便键盘显示,他们可以立即开始键入他们的查询.我尝试在viewWillAppear下面这样做,没有任何运气:
- (void)viewWillAppear:(BOOL)animated
{
[productSearchBar becomeFirstResponder];
[super viewWillAppear:animated];
}
Run Code Online (Sandbox Code Playgroud)
难道还有其他的,我要打电话的地方becomeFirstResponder在UISearchBar或者我应该是别的完全调用的东西吗?
iphone objective-c uiviewcontroller uisearchbar first-responder
我的编辑器设置是textmate但是当我做一个git diff它使用vi向我显示diff输出,有没有办法设置它来显示textmate中的差异?
是否有一个Rails插件或rubygem为您提供了一个为您的Rails应用程序添加api的起点?我们想要使用API Key/Secret Key模型,API也应该是可版本化的.有什么东西可以给我们一些,如果不是全部的话?
我正在尝试检查一个方法是否在一个模块中使用Module.method_defined?(:method)并且它返回false它应该返回true.
module Something
def self.another
1
end
end
Run Code Online (Sandbox Code Playgroud)
Something.methods有'另一个'列出但Something.method_defined?(:another)返回false.
这可能不起作用,因为该方法是在自我定义的吗?如果是这种情况,还有另一种方法可以检查方法是否在模块上定义而不是使用method_defined??
我一直在使用jQuery.svg插件来做一些SVG渲染,它工作得很好,但我也想让服务器将一些SVG渲染到页面中,我无法让它工作.如何在页面中添加如下所示的SVG以便Firefox呈现它?
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div class="map editable" id="map_1"><svg height="600" version="1.1" width="600" xmlns="http://www.w3.org/2000/svg"><image height="600" href="/system/graphics/1/original/floor-plan-large.gif" width="500" x="0" y="0" /><circle cx="300" cy="580" fill="red" r="5" stroke-width="2" stroke="red" /><circle cx="300" cy="400" fill="red" r="5" stroke-width="2" stroke="red" /><circle cx="260" cy="400" fill="red" r="5" stroke-width="2" stroke="red" /><circle cx="260" cy="340" fill="red" r="5" stroke-width="2" stroke="red" /><circle cx="140" cy="340" fill="red" r="5" stroke-width="2" stroke="red" /><polyline fill="none" points="300,580 300,400 260,400 260,340 140,340" stroke-width="3" stroke="blue" /></svg></div>
<svg version="1.1" baseProfile="full" width="300px" height="200px" …Run Code Online (Sandbox Code Playgroud) 我一直在使用zeroMQ,我希望能够通过Internet安全连接.我在ruby中可以使用SSL和/或某种shh连接,但找不到任何如何执行此操作的示例.
我找到了这个旧的stackoverflow链接,zeromq如何与SSL一起工作?说他们正在开展某种安全工作,但那是在一年前,我找不到任何新的参考资料.
即使这不是内置于zeroMQ中,我也会假设有一些方法可以使用OpenSSL或类似方法来设置它.
注意:如果您想要安全传输,zeroMQ网站会提到使用VPN或其他东西.我不想使用VPN.肯定有更好的办法.
我有一个Rails模型的嵌套属性,并且关联验证由于某种原因失败.我没有使用accepts_nested_attributes_for,但我做的事情非常相似.
class Project < ActiveRecord::Base
has_many :project_attributes
def name
project_attributes.find_by_name("name")
end
def name=(val)
attribute = project_attributes.find_by_name("name")
if attribute
attribute.value = val
else
project_attributes.build(:name=>"name", :value=>val)
end
end
end
class ProjectAttribute < ActiveRecord::Base
belongs_to :project
validates_presence_of :name
validates_uniqueness_of :name, :scope => :project_id
validates_presence_of :project_id, :unless => lambda {|attribute| attribute.project.try(:valid?)}
validates_associated :project
end
Run Code Online (Sandbox Code Playgroud)
这是一个人为的例子,但与我想要做的类似.我已经看了一下accepts_nested_attributes_for做了什么,它使用了构建方法,我认为它会将构建的属性与项目相关联.
我还查看了accepts_nested_attributes_for子关联验证失败,这给了我validates_presence_of :unless=>valid?
有关如何使其工作的任何想法?
我正在使用Facebook Connect的网站上工作,最近进行了一些更改,以便主页被缓存,如果您没有登录(使用ajax调用检查),它会加载Facebook Connect javascript并将连接按钮呈现为这页纸.除了Internet Explorer 7和8之外,这在任何地方都能很好地工作.奇怪的是我将按钮渲染为隐藏的"注册/登录"表单,当您显示其中任何一个时,会出现"连接"按钮.你可以看看这里,你会看到Firefox中的按钮,而不是Internet Explorer.如果单击"登录",将显示该按钮.
这是一个Rails应用程序所以在服务器端我们响应一个像这样的rjs的ajax调用:
page['signin-status'].replace(:partial => "common/layout/signin_menu")
page.select('.facebook-connect').each do |value, index|
value.replace(render(:partial => '/facebook/signin'))
end
page << <<-eos
LazyLoader.load('http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php', function(){
FB.init('#{Facebooker.api_key}','/xd_receiver.html');
});
eos
Run Code Online (Sandbox Code Playgroud)
第一行是替换标题,第二行是Modal对话框中的Connect按钮.渲染到标题中的部分内容如下所示:
<span id='signin-status'>
<%= fb_login_button(remote_function(:url => "/facebook/connect"))%> |
<%= link_to_function "Sign In", "showSignInForm();", :id => "signin" %> |
<%= link_to_function "Sign Up", "showSignUpForm();", :id => "signup" %>
</span>
Run Code Online (Sandbox Code Playgroud)
呈现在Modal对话框中的Partial如下所示:
<div class='facebook-connect'>
<div id="FB_HiddenContainer" style="position:absolute; top:-10000px; width:0px; height:0px;" ></div>
<label>Or sign in with your Facebook account</label>
<%= fb_login_button(remote_function(:url => "/facebook/connect"))%>
</div>
Run Code Online (Sandbox Code Playgroud)
我发现显示模态对话框导致显示所有图标非常奇怪.有没有人对正在发生的事情有任何想法或建议?
ruby ×4
javascript ×2
activerecord ×1
ajax ×1
api ×1
api-key ×1
associations ×1
diff ×1
dynamic ×1
facebook ×1
firefox ×1
function ×1
git ×1
html ×1
html5 ×1
iphone ×1
nested ×1
objective-c ×1
performance ×1
security ×1
sockets ×1
ssl ×1
svg ×1
testing ×1
textmate ×1
uisearchbar ×1
validation ×1
xhtml ×1
zeromq ×1