def self.find_all_by_documentable_id(id)
Document.find_all_by_documentable(id)
end
undefined method `find_all_by_documentable' for Document:Class
I've spent hours googling on polymorphism and find, and everyone just
talks about how it just works. Only it doesn't because find_all_by
isn't defined for my polymorphic association. I guess I could do
There is no documentable field defined on Document but
documentable_id, which means you don't need to define your own method,
just call Document.find_all_by_documentable_id(some_id). Hope it
answers your question.
You could do that without the extra documentable field.
class Document < ActiveRecord::Base
#update documentable to true
def documentable
update_attributes(:documentable => 1)
end
#update documentable to false
def not_documentable
update_attributes(:documentable => 0)
end
# check to see if it's true or false
def documentable?
case self.documentable
where 0
"is NOT documentable"
where 1
"is documentable"
end
end
Something like that. and only with a documentable field rather than a polymorphic association which I could only presume would be heavier.