Dec 112009
When talking about templates in Rails, usually people mean the templates which help to re-use views, but this templates is a feature after Rails 2.3 for generating Rails application easily, so give it a try if you haven’t used it yet.
It’s helpful for me to create Rails application according to similar skeleton, a sample below was written about one year ago, but recently I want to create a new application with the same environment/configuration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #idapted_template.rb generate :rspec environment 'config.time_zone = "Beijing"' environment 'config.i18n.default_locale = :zh' name = ask("What's app's name?") file 'config/site_config.yml', <<-CODE app: #{name} domain: mydomain CODE user = ask("What's db user name?") pwd = ask("What's db user password?") file 'config/database.yml', <<-CODE development: adapter: mysql encoding: utf8 database: #{name}_development user: #{user} password: #{pwd} pool: 5 timeout: 5000 test: adapter: mysql encoding: utf8 database: #{name}_test user: #{user} password: #{pwd} pool: 5 timeout: 5000 production: adapter: mysql encoding: utf8 database: #{name}_production user: #{user} password: #{pwd} pool: 5 timeout: 5000 CODE rake 'db:create:all' rake 'db:sessions:create' rake 'db:migrate' gem 'idp_helpers' gem 'idp_core' run "rm public/index.html" run "rm -rf tmp log" run "svn import . http://mydomain.com/svn/projects/applications/#{name} -m 'add new app'" run "rm -rf *" run "svn checkout http://mydomain.com/svn/projects/applications/#{name} ." file 'ignore_list', <<-CODE log tmp nbproject CODE run "svn propset svn:ignore -F ignore_list ." run "rm ignore_list" run "svn commit -m 'set svn ignore'" |
There are several useful commands which help you write powerful templates, you can learn more good examples here. or watch Ryan’s Railscasts about App Templates in Rails 2.3.
Enjoy it.
最新评论