I’m having some problems accessing the ID attribute of an ActiveRecord model. I want to write a method similar to this:
class Category < ActiveRecord::Base
def has_articles?
return true if !Article.find_by_category_id(id).empty?
return false
end
end
But I can’t access the ID of the instance. When I add attr_accessor :id to the class, I have a lot of test failing saying they can’t access category.id.
You should write something like this: