Let’s say you want to create a new Rails app. Every time you run “rails my_app” you usually also do some other steps such as:
# You need to remove the index.html for your app to work: rm public/index.html # Maybe you also create some basic Models everytime: ./script/generate scaffold person name:string # Adding a route to the homepage # route "map.root :controller => :person" # Migrating the database rake db:migrate # The first commit in Git git init git add . git commit -a -m 'Initial commit'
This problem’s gone. Edge Rails now supports a solution using “Templates”. Running a command like this:
rails blog -m ~/template.rb
You’re passing parameters to the ‘rails’ command, telling everything it needs to be done after the creation of the app directory. Things like installing plugins, removing files, putting some default css and image files in /public, the works! So, inside the template.rb file you’d put something like this:
# template.rb run "rm public/index.html" generate(:scaffold, "person name:string") route "map.root :controller => :person" rake("db:migrate") git :init git :add => "." git :commit => "-a -m 'Initial commit'"
Better yet, you can use an URL to the rails command, so from any machine you’re using you’ll always have the initialization commands at your disposal. How great is that?
rails blog -m http://gist.github.com/31208.txt