Gemfile 里面: gem 'rainbows', '~> 4.6.2'
然后 config.ru 里面:
require 'bundler'
Bundler.require
Rainbows::Configurator::Rainbows! do
  use :ThreadSpawn # concurrency model to use
  worker_connections 40
  keepalive_timeout 0 # zero disables keepalives entirely
  client_max_body_size 5*1024*1024 # 5 megabytes
  keepalive_requests 666 # default:100
  client_header_buffer_size 2 * 1024 # 2 kilobytes
end
居然报错 undefined method `Rainbows!' for Rainbows::Configurator:Module (NoMethodError)
我就纳闷了,既然调用到了 Rainbows::Configurator 这个模块说明 gem 引用成功啦,怎么里面的方法不对????求大婶解惑或者说说可能的原因~~
楼主用法有错。。
This module adds Rainbows! to the Unicorn::Configurator Rainbows!-specific configuration options must be inside a the Rainbows! block, otherwise Unicorn::Configurator directives may be used anywhere in the file.
Rainbows! do
  use :ThreadSpawn # concurrency model to use
  worker_connections 400
  keepalive_timeout 0 # zero disables keepalives entirely
  client_max_body_size 5*1024*1024 # 5 megabytes
  keepalive_requests 666 # default:100
  client_header_buffer_size 2 * 1024 # 2 kilobytes
end
# the rest of the Unicorn configuration...
worker_processes 8
stderr_path "/path/to/error.log"
stdout_path "/path/to/output.log"
楼主仔细看下代码
module Rainbows::Configurator
# ...
  # Configures \Rainbows! with a given concurrency model to +use+ and
  # a +worker_connections+ upper-bound.  This method should be called
  # inside a Unicorn/\Rainbows! configuration file.
  #
  # All other methods in Rainbows::Configurator must be called
  # inside this block.
  def Rainbows!(&block)
    block_given? or raise ArgumentError, "Rainbows! requires a block"
    @block = true
    instance_eval(&block)
    ensure
      @block = false
  end
# ...
end
# :enddoc:
# inject the Rainbows! method into Unicorn::Configurator
Unicorn::Configurator.__send__(:include, Rainbows::Configurator)
可以看到Rainbows!方法不是定义在 Rainbows::Configurator 上的 module 级方法,而是实例方法,所以肯定不是这么调用的。
嗯嗯,我想也是这个问题,关键是 new 不了,不知道咋办
class A
  include Rainbows::Configurator
end
r = A.new
r.Rainbows! do
  use :ThreadSpawn # concurrency model to use
  worker_connections 40
  keepalive_timeout 0 # zero disables keepalives entirely
  client_max_body_size 5*1024*1024 # 5 megabytes
  keepalive_requests 666 # default:100
  client_header_buffer_size 2 * 1024 # 2 kilobytes
end
报错:undefined local variable or method `set' for #
module M  
  def my_method  
    'M#my_method()'  
  end  
end  
class C  
  include M  
end  
class D < C; end  
p D.new.my_method() # => "M#my_method()"  
p D.ancestors # => [D, C, M, Object, Kernel, BasicObject]  
文档上的没有说~~~ 就下面几句
Configuration File(s)
Rainbows! will look for the config.ru file used by rackup in APP_ROOT.
For deployments, it can use a config file for Unicorn and Rainbows!-specific options specified by the --config-file/-c command-line switch. Rainbows! accepts all options found in Unicorn::Configurator as well as the “Rainbows!” block, so you can have the following in your config file:
worker_processes 4 # assuming four CPU cores
Rainbows! do
  use :FiberSpawn
  worker_connections 100
end
See the Rainbows! configuration documentation for more details.
我不知道缺了啥?
上面说和 Unicorn 差不多嘛。。楼主先创建一个config/unicorn.rb,然后把配置文件写进去,对于 Rainbow 特有的选项,放在Rainbows!代码块里,应该是这个意思吧。反正我以前是这么用 Unicorn 的。。
rainbow 是容器,app(config.ru)是容器装的内容 你好像不应该把 Rainbow!放在 config.ru 里,就像小心轻放的标签是打在外包装盒上而不是内里面东西上一样
你应该写一个 config/rainbow.rb 写 i 婶写在 config/unicorn.rb
然后用
rainbows -c ./config/rainbow.rb -E production -D
来启动
