I have 2 hstore columns (parameters and keys) defined in my PostgeSQL database. I want to get a list of keys and have defined a method for it in the model:
def self.keys_list
logs = self
list = Log.column_names - %w{id parameters extras}
logs.each do |log|
log.parameters.present? ? list << log.parameters.keys : list << []
log.extras.present? ? list << log.extras.keys : list << []
end
list = list.flatten.uniq
return list
end
But when I try using it, I get the following error:
NoMethodError: undefined method `each' for #<Class:0x00000004b630b0>
Can anyone suggest where the error is or how to do it some other way?
logs = Log.where(name: "Peeyush"). Now, I would like to get the list of keys for it. So, I want to make a call likelogs.keys_liston it.logs = selfbit is very confusing. Just useself.log.parameters.present? ? list << log.parameters.keys : list << []aslist << log.parameters.present? ? log.parameters.keys : []. It removes the repetition and looks nice.