Model's method not being recognized when called

Posted by Brian Roisentul on Stack Overflow See other posts from Stack Overflow or by Brian Roisentul
Published on 2010-03-11T15:07:51Z Indexed on 2010/03/12 13:57 UTC
Read the original article Hit count: 209

I'm using ruby on rails 2.3.2 and also using the acts_as_taggable_on puglin. That generated me two db tables: tags and taggings.

As I didn't need anything more from those, I didn't create a Tag model, for example. Now the project is more mature, I need to create some methods for tags, so I created a Tag model with some methods in it.

The model looks something like this:

class Tag < ActiveRecord::Base

  def self.get_parent
    parent = Tag.find(self.parent_id)

    return parent
  end
end

When I call it from a controller, it won't find the method. This is the code:

tag = Tag.find(tag_id)
the_parent = tag.get_parent

This will throw an error saying:

undefined method `get_parent' for #<Tag id: 13, name: "Historia", parent_id: 12>

I don't know what's wrong. Any help will be appreciated.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about acts-as-taggable