Rails 3:a​​pp模板示例?

Dan*_*hoe 4 ruby-on-rails-3

我想看一个Rails 3的应用程序生成器模板的例子.有什么建议吗?

我对用于生成新Rails应用程序的模板示例感兴趣.Ryan Bates有一个截屏视频(Rails 2.3中的#148 App Templates),它描述了如何为Rails 2.3创建应用程序生成器模板,但我想看看Rails 3中是如何实现类似的.我已经看过几个关于使用的教​​程Rails 3生成器,但我没有找到任何显示如何创建应用程序生成器模板.

我假设Thor和Rails :: Generators :: Actions的所有功能都可用,但我想看看如何在应用程序生成器模板中使用它们.

似乎术语在这里令人困惑."查看模板引擎"(如Haml)是一回事; "Rails Generators"(例如用于"rails generate helper")是另一回事; 和"应用程序生成器模板"(用于"rails new app_name -m some/path/to/template")是另一回事.

Dan*_*hoe 5

在Rails源代码中挖掘并自己回答这个问题:-)

这是Rails 3的应用程序生成器模板的示例:

http://github.com/fortuity/rails3-mongoid-devise/raw/master/template.rb

用法:

rails new app_name -m http://github.com/fortuity/rails3-mongoid-devise/raw/master/template.rb

在自定义此模板时,您可以使用Thor :: Actions提供的任何方法

http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html

和Rails :: Generators :: Actions

http://github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb