ruby - ActiveRecord objects - querying retrieved records -


this puzzling me.

i have:

person = person.find_or_create_by(user_id: some_id) previous_person = person.where('user_id < ?' some_id).limit(1).order('user_id desc') binding.pry 

in pry do:

person.user_id => 12  previous_person.user_id nomethoderror: undefined method `user_id' #<activerecord::relation::activerecord_relation_person:0x007fdd24d635b8> 

why can't access user_id previous_person?

(apologies typos - wasn't direct copy , paste)

doh. can' believe fell again!

of course, person.where returns array.

the correct code previous_person = person.where('user_id < ?' some_id).order('user_id desc').first


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -