通过'-m'参数可以在创建rails项目的时候,应用自己的模板
具体如下:
rails new myapp -m https://raw.githubusercontent.com/kamionayuki/my_rails_app_templates/master/composer.rb
需要注意的是,后面的URL需要用raw
,也就是说在github中,查看https://github.com/kamionayuki/my_rails_app_templates/master/composer.rb
这个文件的时候,点击raw
这个按钮,会生成一个页面,上面的命令需要用到这个页面的URL
composer.rb
的内容如下:
gsub_file "Gemfile", "https://rubygems.org", "http://ruby.taobao.org"
gsub_file "Gemfile", "# gem 'bcrypt', '~> 3.1.7'", "gem 'bcrypt', '~> 3.1.7'"
# gem 'mysql2'
gem 'bootstrap-sass'
gem 'will_paginate-bootstrap'
gem "rails_best_practices"
after_bundle do
inject_into_file 'config/application.rb', after: "# -- all .rb files in that directory are automatically loaded.\n" do <<-'RUBY'
config.i18n.default_locale = "zh-CN"
RUBY
end
inject_into_file 'config/environments/development.rb', after: "# -- all .rb files in that directory are automatically loaded.\n" do <<-'RUBY'
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
RUBY
end
#default zh-CN file
run "wget https://raw.githubusercontent.com/kamionayuki/my_rails_app_templates/master/zh-CN.yml -O config/locales/zh-CN.yml"
# git :init
# git add: '.'
# git commit: "-a -m 'Initial commit'"
end
语法很好懂吧?
run
是用系统的命令
还可以用rake db:migrate
,generate "scaffold", "Post", "title:string"
等指令