This is my code:
class Comment
belongs_to :commentable, polymorphic: true
end
class Video
has_many :comments, as: :commentable
end
class Image
has_many :comments, as: commentable
end
What I am doing:
Comment.search(commentable_title_eq: 'some title').result.to_sql
What I am getting:
NameError: uninitialized constant Comment::Commentable
If I change my code to:
class Comment
belongs_to :commentable, polymorphic: true, class_name: 'Video'
end
It works, but I am breaking the polymorphic association.
Can anyone help please?
Thanks
Please try: commentable_of_Video_type_title_eq, see the wiki for details on Polymorphic Searches.
How would I know which type to search for when writing search form?
@avit I have the same scenario but I not sure how deal with sorting. Kindly assist me.
I am getting Polymorphic associations do not support computing the class.
when I try something in view
= sort_link(@search, :licensee_of_Device_type_quantity, {} , {remote: true})
Please try:
commentable_of_Video_type_title_eq, see the wiki for details on Polymorphic Searches.
What if the type you want to reference is namespaced? :cry:
Most helpful comment
Please try:
commentable_of_Video_type_title_eq, see the wiki for details on Polymorphic Searches.