将 Rails App 的 Gem Source 设置为 Ruby China 源
为了加快 Rails app 中 bundle install 的速度可以将 Ruby China 的 https://gems.ruby-china.com 设置为 Gemfile 的 source :
1 | source 'https://gems.ruby-china.com' |
可以通过以下方法在 rails new 创建新 App 时,自动将 Rails 默认生成的 https://rubygems.org 替换为
https://gems.ruby-china.com :
1 | echo 'gsub_file "Gemfile", "https://rubygems.org", "https://gems.ruby-china.com"' > ~/.rails.template |
~/.railsrc 文件中是执行 rails new 时所使用的命令行选项,例如,如果不希望 rails new 自动执行 bundle install ,可
以在此文件中加入 -B 选项;对于 Rails >= 4.0如果不想使用 spring,可以加入 --skip-spring 选项。
-m 选项是指定一个用于配置 rails new 过程如何生成文件的配置文件,这里就是 ~/.rails.template
~/.rails.template 是一个 Ruby 文件,其中的 gsub_file 方法用于替换Rails App 中的文件。
如果希望 rails new 在生成完所有的文件后,讲 App 目录初始化为一个 git仓库,那么可以在 ~/.rails.template 文件中添加以
下内容:
1 | git :init |
如果是在 OS X 下用 vim 进行 Rails App 的开发,还可以将 OS X / vim 的一些meta/temp 文件加入到 .gitignore 文件中:
1 | curl -Ls https://www.gitignore.io/api/rails >> ~/.rails.gitignore |
然后将 ~/.rails.template 文件修改为:
1 | gsub_file 'Gemfile', 'https://rubygems.org', 'https://gems.ruby-china.com' |
SEE ALSO