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

bax*_*ang 2 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
Run Code Online (Sandbox Code Playgroud)

和我有的错误信息

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'
Run Code Online (Sandbox Code Playgroud)

任何建议/意见?

小智 8

我也遇到了使用Rails 3.1 RC的错误

NameError:
   undefined local variable or method `config'
Run Code Online (Sandbox Code Playgroud)

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

include ActionView::AssetPaths
include ActionView::Helpers::AssetTagHelper
Run Code Online (Sandbox Code Playgroud)

  • @PaulAnnesley同样在这里添加`include Sprockets :: Helpers :: RailsHelper`和`include Sprockets :: Helpers :: IsolatedHelper`(https://github.com/jnicklas/carrierwave/pull/529) (10认同)