How can I force rails to recognize a method's location
I'm having trouble in my application where a controller is calling a method and the server is reporting that the method doesn't exist.
This is the method call. The method not working is tag.related_tags
@related_tags = @t开发者_开发问答ags.collect { |tag| tag.related_tags }.flatten.uniq
The Tag model is originally defined in an plugin acts-as-taggable-on. It is then extended inside of the plugin that contains it, community_engine. Then finally it is extended again in my app directory. The method related_tags is located inside of the community_engine plugin's tag.rb file.
Edits:
Here is the error messageundefined method `related_tags' for #<ActsAsTaggableOn::Tag id: 26, name: "sql">
And the stack trace
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'
Looking at the code of the two plugins you mention I don't think the model hierarchy works how you expect. The CommunityEngine Tag model does not extend ActsAsTaggableOn::Tag
. So, the Tag objects you're working with do not have a related_tags
method defined.
精彩评论