设置 Rails 生成的 Gemfile 中的 gem 源默认为 ruby.taobao.org

来源:互联网 发布:spps统计软件 编辑:程序博客网 时间:2024/04/28 10:44

使用 rubygems.org 官方源安装 gems 实在是一件很痛苦的事,好在阿里做了件好事,为国内的 Rubyists 提供了一个 gems 镜像。但是在使用rails new 生成新的项目时,生成的Gemfile 中的源地址是 rubygems.org 官方源,而且总会自动运行bundle install,我们可以 rails 库中的application generator 中的 Gemfile 模板,将其中的 source 选项的值改为:http://ruby.taobao.orgapplocation generator 中的Gemfile模板的位置:

shell 代码:
cd "$(gem environ | gawk '/INSTALLATION DIR/{print $4}')"cd ./gems/railties-*/lib/rails/generators/rails/app/templatesvim ./Gemfile

修改完成后的 Gemfile 模板为(rails-4.0.1):

~/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.1/lib/rails/generators/rails/app/templates/Gemfile
source 'http://ruby.taobao.org'<%= rails_gemfile_entry -%><%= database_gemfile_entry -%><%= assets_gemfile_entry %><%= javascript_gemfile_entry -%># Build JSON APIs with ease. Read more: https://github.com/rails/jbuildergem 'jbuilder', '~> 1.2'group :doc do  # bundle exec rake doc:rails generates the API under doc/api.  gem 'sdoc', require: falseend# Use ActiveModel has_secure_password# gem 'bcrypt-ruby', '~> 3.1.2'# Use unicorn as the app server# gem 'unicorn'# Use Capistrano for deployment# gem 'capistrano', group: :development<% unless defined?(JRUBY_VERSION) -%># Use debugger# gem 'debugger', group: [:development, :test]<% end -%>

如果需要修改模板中的其他默认设置,也可以在这里修改。

注意:这个方法的问题是当你升级 Rails 之后,修改过的模板会被新版本的 Rails 中的模板覆盖掉,到时候还需要重新修改。



=============================================================================

现在的地址为https://gems.ruby-china.org/




0 0