包含在模型中的辅助方法产生“未定义的局部变量或方法‘config’ for"错误 [英] helper method included in a model produces "undefined local variable or method `config' for" error
本文介绍了包含在模型中的辅助方法产生“未定义的局部变量或方法‘config’ for"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常复杂的辅助方法,它也需要出现在模型中.我只是在我的模型中包含了一些帮助程序,但同样的方法不适用于 Rails 3.0.7.
I have a quite complex helper method that is also needed to be in a model. I've done it with just including some helpers in my model, but the same approach is not working on Rails 3.0.7.
module ContentsHelper
def content_teaser record
# it uses image_tag, truncate, raw, and some others.
end
end
class Content < ActiveRecord::Base
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
include ActionController::UrlFor
include ActionView::Helpers::TextHelper
include ActionView::Helpers::RawOutputHelper
include ActionView::Helpers::AssetTagHelper
include ContentsHelper
include Rails.application.routes.url_helpers
def teaser
content_teaser self.body
end
end
以及我的错误信息
undefined local variable or method `config' for #<Content:0x10bac7248>
app/helpers/contents_helper.rb:8:in `content_teaser'
app/models/content.rb:70:in `teaser'
有什么建议/建议吗?
推荐答案
我也遇到了使用 Rails 3.1 RC 的错误
I also got hit with the error working with Rails 3.1 RC
NameError:
undefined local variable or method `config'
一些 Rails 源代码跟踪,我发现缺少 include ActionView::AssetPaths.
Some Rails source tracing and I discovered the missing include ActionView::AssetPaths.
include ActionView::AssetPaths
include ActionView::Helpers::AssetTagHelper
这篇关于包含在模型中的辅助方法产生“未定义的局部变量或方法‘config’ for"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文