简体   繁体   English

如何在gem中覆盖Rails 3模板

[英]How to override a rails 3 template within a gem

I have a Rails 3 project where I override some scaffold templates. 我有一个Rails 3项目,在其中我覆盖了一些脚手架模板。 This is done by placing a new template in lib/templates/erb/scaffold and adding lib to my autoload path in config/application.rb (see Rasilscasts #216). 这是通过在lib / templates / erb / scaffold中放置一个新模板并将lib添加到config / application.rb中我的自动加载路径来完成的(请参见Rasilscasts#216)。

Now, I'd like to package my work in a gem. 现在,我想将我的作品打包成一个宝石。 (I'm new to gems...) (我是宝石新手...)

I cannot figure out how to accomplish this in a gem. 我无法弄清楚如何做到这一点。

Looking at generators.rb I see there is a configuration for templates dir: 查看generators.rb,我看到模板dir有一个配置:

  templates_path.concat config.templates
  templates_path.uniq!

but I'm not sure how to use it. 但我不确定如何使用它。

I don't think I'm supposed to mess with the lib dir from a gem (or even if I can do that). 我不认为我应该弄乱gem的lib目录(或者即使我可以做到)。

So my question is, how do I accomplish this from a gem? 所以我的问题是,如何从宝石中做到这一点?

Thanks in advance 提前致谢

jeff 杰夫

Instead of adding lib to your autoload_path you add your gem's lib directory (though I think this should happen automatically). 无需将lib添加到autoload_path而是添加gem的lib目录(尽管我认为这应该自动发生)。 If you provide some code excerpts I can probably give more specific advice, though 如果您提供一些代码摘录,我可能会给出更具体的建议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM