Answer the question
In order to leave comments, you need to log in
Rails ActiveRecord method?
Hello. Do not tell me how to implement it correctly, there is a class method in ActiveRecord.
And how can it be reached if its name is passed in a variable. Thanks
# Поля базы
user.userable_type # 'Institution'
user[ :userable_type ] # 'Institution'
# Мотод класса
user.is_institution? # true
user[ :is_institution? ] # nil
class User < ApplicationRecord
def is_institution?
self.userable_type == 'Institution'
end
end
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question