我在活动记录类上有一个方法,它为消息传递系统呈现 ERB 模板。简化的代码如下所示:
ERB.new(template).result(binding)
其中binding
是 ActiveRecord 模型对象的当前 Binding,template
是从文件系统中读取的 erb 模板文件。
我想在模板中使用一些命名路由,但无法使命名路由可用。
我已经看到所有帖子都说在当前的 ActiveRecord 模型中包含/需要以下各种组合(或者最好作为单例):
include ActionView::Helpers::TagHelper
include ActionView::Helpers::AssetTagHelper
include ActionController::UrlWriter
require 'action_controller/routing'
include ActionController::Routing
include ActionController::Routing::Routes
include ActionController::Routing::NamedRoutes
其中一些错误,我认为根本不正确......其他我看不到任何好处,因为路线仍然不起作用。有人有想法吗?