我在规范中有以下代码:
it 'should save some favorite locations' do
user=FactoryGirl.create(:user) # not adding anything
Run Code Online (Sandbox Code Playgroud)
它似乎没有写任何东西到数据库.FactoryGirl是否打算在模型规范中写一些东西?如果我从rails控制台运行,它会添加到数据库中.为什么rspec中的测试没有运行呢?它是如何工作的?
谢谢
我试图检查字符串是否全部,a-zA-Z0-9但这不起作用.知道为什么吗?
var pattern=/^[a-zA-Z0-9]*$/;
var myString='125 jXw'; // this shouldn't be accepted
var matches=pattern.exec(myString);
var matchStatus=1; // say matchStatus is true
if(typeof matches === 'undefined'){
alert('within here');
matchStatus=0; // matchStatus is false
};
if(matchStatus===1){
alert("there was a match");
}
Run Code Online (Sandbox Code Playgroud) 我正在为生产部署一个rails应用程序,所以宝石进入共享/捆绑.mysql2 gem似乎在Ubuntu12.04中有问题,所以我想删除它并重新安装,但我该怎么办呢?我不能打电话gem uninstall mysql2.我试过bundle exec gem uninstall mysql2 --path shared/bundle但得到了错误Could not locate Gemfile.我该如何删除?如果您还需要更多信息,请使用lmk.
thx提前
我正在使用一个名为auth_token的自定义标头,我将其传递给我的rails后端.在localhost/webrick上,我可以访问:
curl -H "auth_token: r5O_IdqpWStqmJFe0pil0Q" http://localhost:3000
Run Code Online (Sandbox Code Playgroud)
并且可以使用以下标题访问标头值:
auth_token=request.headers["auth_token"] if request.headers["auth_token"].
Run Code Online (Sandbox Code Playgroud)
但是,当我访问staging(nginx/passenger)时:
curl -H "auth_token: r5O_IdqpWStqmJFe0pil0Q" http://staging.domain.com/
Run Code Online (Sandbox Code Playgroud)
它无法访问标头值.我需要对nginx/passenger进行任何配置以允许它访问此自定义标头吗?
谢谢
我在AFNetworking getPath调用的成功块中有以下内容:
+(void)allItemsWithBlock: (void (^)(NSArray *items)) block
{
...
NSMutableArray *mutableItems = [NSMutableArray array];
for (NSDictionary *attributes in [responseObject valueForKey:@"data"]) {
Item *item = [[Item alloc] initWithAttributes:attributes];
[mutableItems addObject:item];
}
NSLog(@"here is a count: %i", [mutableItems count]);
if(block){
block(mutableItems);
}
Run Code Online (Sandbox Code Playgroud)
并且在传入的块中,我有以下内容但是将错误列为注释:
[Item allItemsWithBlock:^(NSArray *items){
for(Item *thisItem in *items){ // The type 'NSArray' is not a pointer to a fast-enumerable object
NSLog(@"in the block here");
}
}];
Run Code Online (Sandbox Code Playgroud)
我已经读过尝试快速枚举但不确定问题是什么.NSMutableArray - > NSArray是一个问题吗?是因为这个数组是在一个块中创建的,因此可能被视为可能仍然"开放变化"?我之前在项目中看到过这样的代码,似乎不是问题.
thx任何帮助
我有
-(void)saveAsset:(NSUInteger) assetID
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"asset_id": assetID};
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误:
Collection element of type 'NSUInteger' (aka 'unsigned long') is not an Objective-C object
Run Code Online (Sandbox Code Playgroud)
我怎么指定这个?我试过了:
NSDictionary *parameters = @{@"asset_id": [assetID integerValue]};
Run Code Online (Sandbox Code Playgroud)
和
NSDictionary *parameters = @{@"asset_id": (id)assetID};
Run Code Online (Sandbox Code Playgroud)
但他们都没有工作.
谢谢
我想创建一个这样的按钮:
import UIKit
class EKLikeButton: UIButton {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.layer.cornerRadius = 5.0;
self.layer.borderColor = UIColor.redColor().CGColor
self.layer.borderWidth = 1.5
self.backgroundColor = UIColor.blueColor()
self.tintColor = UIColor.whiteColor()
}
}
Run Code Online (Sandbox Code Playgroud)
但实现它的唯一方法似乎是在Storyboard中设置一个预先存在的按钮.我希望能够做到:
let btn = EKLikeButton()
btn.frame=CGRectMake(10.0, 10.0, 40.0, 40.0)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试上述内容时,我明白了
在调用中缺少参数'coder'的参数
我如何创建一个可以从Swift中的代码或故事板处理的init函数?
我希望有两个内联块,第二个是vertical-align:bottom但是高达10个像素.我不确定我会怎么做.我在想这样的事情但是如何将test2类移动10像素呢?
.test1{
display:inline-block;
border: 1px solid red;
min-height: 50px;
}
.test2{
display:inline-block;
border: 1px solid blue;
vertical-align:bottom;
}Run Code Online (Sandbox Code Playgroud)
<div class='outer'>
<div class='test1'>
here is some info
</div>
<div class='test2'>
here is more info
</div>
</div>Run Code Online (Sandbox Code Playgroud)
我创建了这个片段http://jsfiddle.net/PexkV/
<script>
var arc={};
arc.handler={
background_color:'#8DBC8F',
console_this: function(str){
alert('lets write this to the console ' + str + ' ' + this.background_color);
}
}
$(document).ready(function(){
$('.more-click-me').on('click', arc.handler.console_this('here'));
$('.more-click-me').on('click', function(){
arc.handler.console_this('blue');
});
});
</script>
<div class='more-click-me'>lets write this</div>
Run Code Online (Sandbox Code Playgroud)
并且我不确定为什么第一个事件被自动调用(示例中的"here").它似乎只应该响应点击而被调用?我得不到什么?如果我做了一些非常愚蠢的语法问题,请提前抱歉.
thx提前
可能重复:
如何将nsstring转换为uicolor?
不是一个客观的程序员,但我不确定我不能做这样的事情.我知道我正在返回一个字符串值,但只是想要一种简洁的方法来获取这些值:
NSMutableArray *colorsArray=[[NSMutableArray alloc] init];
[colorsArray addObject:@"whiteColor"];
[colorsArray addObject:@"blueColor"];
// val5 is either 0 or 1
[view setBackgroundColor:[UIColor [colorsArray objectAtIndex:val5]]];
Run Code Online (Sandbox Code Playgroud)
这可能吗?
thx提前
objective-c ×3
ios ×2
javascript ×2
bundler ×1
capistrano ×1
css ×1
jquery ×1
nginx ×1
passenger ×1
rspec ×1
rvm ×1
swift ×1
uibutton ×1