模型中包含的辅助方法为“错误”生成“未定义的局部变量或方法`config'

时间:2011-06-09 08:41:54

标签: ruby-on-rails-3

我有一个非常复杂的辅助方法,也需要在模型中。我已经在我的模型中包含了一些帮助程序,但是同样的方法不适用于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'

任何建议/意见?

1 个答案:

答案 0 :(得分:8)

我也遇到了使用Rails 3.1 RC

的错误
NameError:
   undefined local variable or method `config'

一些Rails源跟踪,我发现缺少包括ActionView :: AssetPaths。

include ActionView::AssetPaths
include ActionView::Helpers::AssetTagHelper