在哪里可以找到脚手架生成的模型模板?
我想对 Rails 使用的 Model
生成器/脚手架进行 Costumize,例如:
rails generate model ModelName field:field_tyle,...
rails generate scaffold ModelName field:field_type,...
假装某些区域,当我完成对模板的 cosutumizing 时,它应该看起来像这样。
class ModelName < ActiveRecord::Base
# ASSOCIATIONS
# VALIDATIONS
# ATTR RELATED STUFF
# INSTANCE METHODS
# CLASS METHODS
end
而不是:
class ModelName < ActiveRecord::Base
end
找到脚手架使用的 View
模板很容易,但找到模型的模板却不那么容易。我在哪里可以找到它,或者是否“仅”有一个生成器可以实现此目的?何时可以对其进行定制?
I want to costumize the Model
generator/scaffolder that is used by rails e.g.:
rails generate model ModelName field:field_tyle,...
rails generate scaffold ModelName field:field_type,...
to pretend some areas and it should look like this when Im done cosutumizing the template.
class ModelName < ActiveRecord::Base
# ASSOCIATIONS
# VALIDATIONS
# ATTR RELATED STUFF
# INSTANCE METHODS
# CLASS METHODS
end
instead of:
class ModelName < ActiveRecord::Base
end
It was easy to find the View
Templates used by the scaffolder but its not that easy to find the template for the Model. Where can I find it or is there "only" a generator for this and when how can I costumize it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个关于自定义 Rails 生成器的指南 Rails Guides。您可以在 Rails API 检查文件位置,只需知道类名,您也可以检查 漂亮的生成器 作者:Ryan Bates
there is a guide on customizing rails generators Rails Guides. File location you can check at Rails API just need to know class name also you can check nifty generators by Ryan Bates
我遇到了类似的问题,需要做一些事情,但这对我有用。
Rails 3.1 的 ActiveRecord 模型生成器模板如下:
lib/templates/active_record/model/
这可以是 model.rb、migration.rb 或 module.rb
我想 DataMapper 或 MongoMapper 位于类似的位置。希望这有帮助。
I had a similar issue it took some doing but this work for me.
The ActiveRecord model generator templates for Rails 3.1 go in:
lib/templates/active_record/model/
This could be either model.rb, migration.rb or module.rb
I imagine that DataMapper or MongoMapper go in analogous locations. Hope this helps.