Rails 的环境特定初始化程序?
您可以将 Rails 配置为仅在某些环境下运行初始化程序吗? 就我而言,我必须破解回形针才能在我的开发盒上使用 Imagemagick,因此我有经过猴子修补的代码,我只想应用于开发环境,而不是生产环境。 该猴子补丁保存为 config\initializers 中的文件。
guides.rubyonrails.org 站点并未表明可以执行此操作。 如果我不能,我想我不会将此补丁签入我的存储库,但这并不理想。
Can you configure rails to only run an initializer under certain environments? In my case I had to hack paperclip to work with Imagemagick on my dev box, so I have monkeypatched code I want only to apply to the development environ, not the production environment. That monkeypatch is saved as a file in config\initializers.
The guides.rubyonrails.org site does not indicate that one can do this. If I can't I suppose I just won't check this patch into my repo, but that would not be ideal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将其放在 config/environments/development.rb 中的 after_initialize 块中,或者只是用 if Rails.env.development? 包围它在你已经拥有的初始化程序中。
我认为其中任何一个都适合你。
You could put this in an
after_initialize
block inconfig/environments/development.rb
, or just surround it withif Rails.env.development?
in the initializer you already have.I think either of these would work for you.