小编tim*_*one的帖子

FactoryGirl是否会在每次创建时创建记录; 从控制台工作而不是在rspec中

我在规范中有以下代码:

it 'should save some favorite locations' do
  user=FactoryGirl.create(:user)  # not adding anything
Run Code Online (Sandbox Code Playgroud)

它似乎没有写任何东西到数据库.FactoryGirl是否打算在模型规范中写一些东西?如果我从rails控制台运行,它会添加到数据库中.为什么rspec中的测试没有运行呢?它是如何工作的?

谢谢

rspec ruby-on-rails ruby-on-rails-3

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

用于检查字符串是否为a-zA-Z0-9的正则表达式

我试图检查字符串是否全部,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)

javascript

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

如何使用capistrano从生产部署中卸载gem

我正在为生产部署一个rails应用程序,所以宝石进入共享/捆绑.mysql2 gem似乎在Ubuntu12.04中有问题,所以我想删除它并重新安装,但我该怎么办呢?我不能打电话gem uninstall mysql2.我试过bundle exec gem uninstall mysql2 --path shared/bundle但得到了错误Could not locate Gemfile.我该如何删除?如果您还需要更多信息,请使用lmk.

thx提前

capistrano bundler rvm ruby-on-rails-3 rvm-capistrano

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

nginx/passenger配置允许访问自定义标头

我正在使用一个名为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进行任何配置以允许它访问此自定义标头吗?

谢谢

ruby-on-rails passenger nginx

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

从块返回的NSArray/NSMutableArray上的快速枚举

我在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任何帮助

objective-c

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

尝试将NSUInteger分配给字典文字时出错

我有

-(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)

但他们都没有工作.

谢谢

objective-c

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

从代码和Storyboard实例化自定义按钮 - 如何创建init方法

我想创建一个这样的按钮:

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函数?

uibutton ios swift

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

如何做一个vertical-align:bottom但是10px

我希望有两个内联块,第二个是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)

css

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

不确定为什么在这里触发这个jQuery click事件

我创建了这个片段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提前

javascript jquery

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

我不确定如何使用objectAtIndex执行此操作

可能重复:
如何将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 ios

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