To check if a class or instance variable to see if it has an attribute we can use the ruby method has_attribute?(:method_name)

However, when we are dealing with an instance of ActiveRecord in Rails, sometimes we may come across situation when we want to see if a instance variable has a belongs_to or has_many relationship with other models. In that case, we can make use of


This solution is more generic and feasible in order to avoid no method error in Rails.