mongrel.rb

使用Redmin1.3.2时,用命令行可以启动,但使用mongrel_service-0.4.0启动后会发生重定向
只需要将mongrel.rb拷贝到redmine-1.3.2\config\initializers下面就好了

mongrel.rb

if ['2.3.8', '2.3.9', '2.3.10', '2.3.11', '2.3.14'].include?(Rails.version) && Gem.available?('mongrel', '~>1.1.5') && self.class.const_defined?(:Mongrel)
  
  # Pulled right from latest rack. Old looked like this in 1.1.0 version.
  #
  # def [](k)
  # super(@names[k] ||= @names[k.downcase])
  # end
  #
  module Rack
    module Utils
      class HeaderHash < Hash
        def [](k)
          super(@names[k]) if @names[k]
          super(@names[k.downcase])
        end
      end
    end
  end
  
  # Code pulled from the ticket above.
  #
  class Mongrel::CGIWrapper
    def header_with_rails_fix(options = 'text/html')
      @head['cookie'] = options.delete('cookie').flatten.map { |v| v.sub(/^\n/,'') } if options.class != String and options['cookie']
      header_without_rails_fix(options)
    end
    alias_method_chain :header, :rails_fix
  end
  
  # Pulled right from 2.3.8 ActionPack. Simple diff was
  #
  # if headers.include?('Set-Cookie')
  # headers['cookie'] = headers.delete('Set-Cookie').split("\n")
  # end
  #
  # to
  #
  # if headers['Set-Cookie']
  # headers['cookie'] = headers.delete('Set-Cookie').split("\n")
  # end
  #
  module ActionController
    class CGIHandler
      def self.dispatch_cgi(app, cgi, out = $stdout)
        env = cgi.__send__(:env_table)
        env.delete "HTTP_CONTENT_LENGTH"
        cgi.stdinput.extend ProperStream
        env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
        env.update({
          "rack.version" => [0,1],
          "rack.input" => cgi.stdinput,
          "rack.errors" => $stderr,
          "rack.multithread" => false,
          "rack.multiprocess" => true,
          "rack.run_once" => false,
          "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
        })
        env["QUERY_STRING"] ||= ""
        env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
        env["REQUEST_PATH"] ||= "/"
        env.delete "PATH_INFO" if env["PATH_INFO"] == ""
        status, headers, body = app.call(env)
        begin
          out.binmode if out.respond_to?(:binmode)
          out.sync = false if out.respond_to?(:sync=)
          headers['Status'] = status.to_s
          if headers['Set-Cookie']
            headers['cookie'] = headers.delete('Set-Cookie').split("\n")
          end
          out.write(cgi.header(headers))
          body.each { |part|
            out.write part
            out.flush if out.respond_to?(:flush)
          }
        ensure
          body.close if body.respond_to?(:close)
        end
      end
    end
  end
end

搭建Redmine

1.下载Ruby1.87及DevKit,解压,并将两个bin目录加入到PATH
http://rubyinstaller.org/downloads/

2.下载RubyGems 1.3.7,并安装

ruby setup.rb

3.安装gem
1)安装Rails 2.3.14

gem install rails -v=2.3.14 --include-dependencies

2)安装rake

gem install rake --include-dependencies

3)安装rack

gem install rack

4)安装mysql插件

gem install mysql

5)安装rdoc

gem install rdoc

6)安装i18n

gem install i18n

如果网速很差,可以把gem下载到本地后再安装,比如:

gem install i18n -l

4.配置数据库
1)拷贝dll
将mysql安装目录下的libmysql.dll拷贝到ruby路径
如果你的libmysql.dll版本高于5.1.3的话请用这个
http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll

2)配置数据库
下载并解压redmine-1.3.2
拷贝database.yml.example为database.yml,将production小节配置好

3)创建数据库

rake generate_session_store
rake db:migrate RAILS_ENV="production"

5.测试

ruby script/server -e production
#访问http://localhost:3000/
#用户名:admin
#密码:admin

6.配置email
拷贝configuration.yml.example为configuration.yml,
修改smtp配置,重启服务器即可

7.安装服务
1)安装gem

gem install mongrel_service

2)安装服务

mongrel_rails service::install -N Redmine -c D:\Ruby\redmine-1.3.2 -p 3000 -e production

3)设置服务依赖

sc config Redmine depend= MySQL start= auto

4)将mongrel.rb拷贝到redmin/config/initializers
mongrel.rb在github上有很多版本,但要自己改一下代码,来适应自己的rails版本