在哪里可以找到脚手架生成的模型模板?

发布于 2024-12-21 10:21:12 字数 612 浏览 2 评论 0原文

我想对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

却一份温柔 2024-12-28 10:21:12

有一个关于自定义 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

瞳孔里扚悲伤 2024-12-28 10:21:12

我遇到了类似的问题,需要做一些事情,但这对我有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文