小编bon*_*fer的帖子

unicorn nginx上游服务器无法启动

我的独角兽服务器运行正常,但已停止工作,我无法弄清楚如何重新启动它.

2011/04/18 15:23:42 [error] 11907#0: *4 connect() to unix:/tmp/sockets/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: 71.131.237.122, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/sockets/unicorn.sock:/", host: "tacitus"

我的配置文件位于:https://gist.github.com/926006

任何有关我的故障排除选项应该是什么的帮助将不胜感激.

最好,

蒂姆

ubuntu nginx unicorn

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

matlab初始化对象数组

我在MATLAB中玩OOP,我有以下构造函数:

function obj = Squadron(num_fighters, num_targets, time_steps)            
    if nargin == 0
        num_targets = 100;
        time_steps = 100;
        num_fighters = 10;
    end
    obj.num_shooters = num_fighters;
    for iShooter = 1:obj.num_shooters
       a(iShooter) = Shooter(num_targets, time_steps);
    end
    obj.ShooterArray = a;
    obj.current_detections = zeros(num_fighters, num_targets);
end

那个临时变量'a'闻起来很可怕.有没有更好的方法来初始化一个对象数组,我希望有一个推/弹方法.我相信有更好的方法可以做到这一点.

arrays oop matlab

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

Mongoid has_and_belongs_to_many关联

我试图让mongoid保存关联,但我只能让一方工作.如果我有以下测试.

  test "should add a user as a follower when a user follows the group" do                                                                                                                                        
    @cali_group.followers = []                                                                                                                                                
    @user1.followed_groups << @cali_group                                                                                                                                                  
    assert_equal 1, @user1.followed_groups.count
    assert_equal 1, @cali_group.followers.count
  end
Run Code Online (Sandbox Code Playgroud)

哪个失败了,因为@ cali_group.followers是[].我已经使用了一段时间,尝试过@cali_group.reload.但看起来在我的代码中执行此操作的唯一方法是使用连接的两端,即@cali_group.followers << @user1.如果必须的话,我可以在我的代码中这样做.

polco_group和用户的模型如下:https://gist.github.com/1195048

完整的测试代码在这里:https://gist.github.com/1195052

ruby mongoid ruby-on-rails-3 ruby-on-rails-3.1

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

FactoryGirl属于_to协会

我有一个工厂,我在其中定义了一个位置factories/locations.rb.我正在使用Mongoid和Rails 3.1.1和ruby 1.9.3.

FactoryGirl.define do
  factory :location do
      name Faker::Name.name
      description "Down by the river"
    end
end

然后我想定义一个属于一个位置的健身营(因此具有location_id属性).

FactoryGirl.define do
  factory :fitness_camp do
    title "Parkour"
    association :location_id, :factory => :location
  end
end

这是有效的,但是,这是我的黑客攻击的结果,而不是我在文档中读到的.从入门指南(https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md)看来,这应该是这样简单:

  factory :fitness_camp do
    title "Parkour"
    location
  end

我错过了什么吗?这是否表示我的模型可能配置不正确?

谢谢!

蒂姆

ruby-on-rails mongoid factory-bot

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

rubymine注释掉rails代码

在RubyMine的很容易与代码编写出来的HTML - >在线评论,但你对此有何评论中的红宝石多行.

%= "this is a test %>

#= "this is a test %>

ruby-on-rails rubymine

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

rubymine在调试时崩溃

在使用我当前的gemset几个月的良好操作后,我昨天开始收到以下错误:

/Users/Tim/.rvm/rubies/ruby-1.9.2-p290/bin/ruby -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/Tim/.rvm/gems/ruby-1.9.2-p290@cba/bundler/gems/ruby-debug-ide-c3a7a8529ae6/bin/rdebug-ide --port 57803 -- /Users/Tim/Sites/cba/script/rails server -b 0.0.0.0 -p 3000 -e development
Fast Debugger (ruby-debug-ide 0.4.17.beta8, ruby-debug-base 0.11.28) listens on 127.0.0.1:57803
=> Booting WEBrick
=> Rails 3.1.0.rc5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-08-17 15:59:51] INFO  WEBrick 1.3.1
[2011-08-17 15:59:51] INFO  ruby 1.9.2 (2011-07-09) [x86_64-darwin10.8.0]
[2011-08-17 15:59:51] INFO  WEBrick::HTTPServer#start: pid=34611 port=3000
/Users/Tim/.rvm/gems/ruby-1.9.2-p290@cba/bundler/gems/ruby-debug-ide-c3a7a8529ae6/lib/ruby-debug/xml_printer.rb:80: [BUG] Segmentation fault
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

-- control frame ---------- …

debugging rubymine ruby-on-rails-3

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

是否有可能使用不是明确任务的Thor方法

我有一个使用多种方法的Thor脚本

class Update < Thor
   desc "do_it", "a simple task"
   def do_it
     puts i_did_it
   end

   # no desc here !!!
   def i_did_it
     "I did it"
   end 
end

这可能吗?如果没有显式任务,则无法正确构建任务列表.

谢谢,

蒂姆

ruby ruby-on-rails thor

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

用正则表达式搜索单元格数组

我经常发现自己试图搜索单元格数组,就像我想用sql查询搜索数据库一样.在这种情况下,我有一些军事基地(bases.shp)

bases = shaperead('us-military-bases.shp')

然后我想过滤掉形状文件以获得空军基地,就像这样regexp({bases.FAC_NAME}','Air Force').但我得到的输出是相当麻烦的:

[]
[]
[ 4]
[]
[]
[ 9]
[]
Run Code Online (Sandbox Code Playgroud)

我确信过滤单元格数组或shapefile很常见,必须有一些好的做法.感谢您的任何见解.

我也在尝试这样的事情:

trif = arrayfun(@(x)regexp(x.FAC_NAME,'Griff','match'),af_bases)
Run Code Online (Sandbox Code Playgroud)

matlab

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

使用rails3模拟外部API对象

我想模拟/存根:

@the_bill = GovKit::OpenCongress::Bill.find_by_idents("112-s368").first

用于我的测试.

返回我想要为我的测试目的修复的以下对象:

--- !ruby/object:GovKit::OpenCongress::Bill 
bill_type: s
co_sponsors: 
- !ruby/object:GovKit::OpenCongress::Person {}

id: 68340
introduced: 1297836000
most_recent_actions: 
- result: 
  created_at: "2011-02-17T07:45:50Z"
  govtrack_order: 
  amendment_id: 
  text: Read twice and referred to the Committee on Agriculture, Nutrition, and Forestry.
  date: 1297836000
  how: 
  id: 287979
  vote_type: 
  type: BillAction
  roll_call_id: 
  action_type: action
  datetime: "2011-02-16T00:00:00Z"
  where: 
  bill_id: 68340
  roll_call_number: 
- result: 
  created_at: "2011-02-17T07:45:49Z"
  govtrack_order: 
  amendment_id: 
  text: 
  date: 1297836000
  how: 
  id: 287978
  vote_type: 
  type: BillAction
  roll_call_id: 
  action_type: introduced
  datetime: "2011-02-16T00:00:00Z"
  where: 
  bill_id: 68340
  roll_call_number: 
number: …

ruby-on-rails mocking ruby-on-rails-3

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

测试没有内容的字符串

我想向一个测试no_content的ruby字符串对象发送一条消息:

"".content? => false # same as .empty?
"   ".content? => false # same as .blank?
"\n\t".content? => false # new feature
Run Code Online (Sandbox Code Playgroud)

具体来说,content?如果有人可以在那里阅读,那么会通过.我将修补String类以使用正则表达式执行此操作.

"\n\t\n\n".gsub(/[\n|\t]/,'').empty?
Run Code Online (Sandbox Code Playgroud)

这让我很接近,但我可能会重新发明轮子,并希望有一个更完整的解决方案.

ruby regex string ruby-on-rails

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