【问题标题】:How can I force rails to recognize a method's location如何强制导轨识别方法的位置
【发布时间】:2010-07-29 20:24:48
【问题描述】:

我的应用程序遇到问题,其中控制器正在调用方法,而服务器报告该方法不存在。

这是方法调用。不起作用的方法是tag.related_tags

@related_tags = @tags.collect { |tag| tag.related_tags }.flatten.uniq

标签模型最初是在一个插件中定义的,即作为可标记的。然后在包含它的插件 community_engine 中扩展它。最后它在我的应用程序目录中再次扩展。方法related_tags 位于community_engine 插件的tag.rb 文件中。

编辑:
这是错误信息

undefined method `related_tags' for #<ActsAsTaggableOn::Tag id: 26, name: "sql">

还有堆栈跟踪

c:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/attribute_methods.rb:260:in `method_missing'
c:/Users/Teddy/railCode/careercup/app/controllers/tags_controller.rb:80:in `show'
c:/Users/Teddy/railCode/careercup/app/controllers/tags_controller.rb:80:in `collect'
c:/Users/Teddy/railCode/careercup/app/controllers/tags_controller.rb:80:in `show'

【问题讨论】:

  • 您能否粘贴显示缺少方法异常的堆栈跟踪?可能@tags 由 Array 对象组成,而不是 Tag 对象。

标签: ruby-on-rails routes ruby-on-rails-plugins acts-as-taggable-on


【解决方案1】:

查看您提到的两个插件的代码,我认为模型层次结构并不像您期望的那样工作。 CommunityEngine 标签模型不扩展ActsAsTaggableOn::Tag。因此,您正在使用的 Tag 对象没有定义 related_tags 方法。

【讨论】:

  • 在 CommunityEngine 标签内我放了require_dependency File.dirname(__FILE__) + '/../../plugins/acts_as_taggable_on/lib/acts_as_taggable_on/tag.rb' 我也在使用插件沙漠,如果我理解正确的话,它负责扩展模型。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-27
  • 1970-01-01
  • 1970-01-01
  • 2021-01-04
相关资源
最近更新 更多