通過'-m'參數(shù)可以在創(chuàng)建rails項(xiàng)目的時候,應(yīng)用自己的模板
具體如下:
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
這個文件的時候,點(diǎn)擊raw
這個按鈕倍踪,會生成一個頁面索昂,上面的命令需要用到這個頁面的URL
composer.rb
的內(nèi)容如下:
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
是用系統(tǒng)的命令
還可以用rake db:migrate
,generate "scaffold", "Post", "title:string"
等指令