1

I was thinking about being able to add an "application name" method to my Rails::Application subclass, since the method that I had originally added to a helper for ApplicationController is no longer visible to my ActionMailer.

ActionView::Template::Error: undefined local variable or method `app_name' for #<#<Class:0x44aba18>:0x449b8f0>

I haven't seen any reference to doing this in the standard rails tutorials, and a few Google queries don't indicate best or even acceptable practice.

I'd rather not have to hard code a lot of global application settings that may be of value in the mailer templates.

4

1 回答 1

0

只要您在应用程序配置中“从外部”执行此操作,那么依赖项就是轻量级的,您可以使用新的 Rails 版本来维护它。如果由于某种原因你很紧张,你可以把它放在 a 中lib,但由于显而易见的原因,这可能会让人感觉更尴尬。

如果应用程序非常广泛地使用新方法,我属于将扩展原始类(如 String)的阵营。有些人不会;我听到的最常见的论点是“内存问题”——鉴于该应用程序的广泛使用,我永远无法理解。

于 2013-09-05T17:13:34.793 回答