Rails 4 - find_by_* does not work in a rake task -


i'm running rake task , stop byebug upon creation of last product.

then strange discrepancies between output in rake task buebug , rails console.

product.count works both in console , byebug, product.find_by_id works in console. in rake task returns nil.

so far replaced find_by_* methods where, validations pass , rake task job.

googling didn't help. strange because use find_by_* in quite few places. finding out validations in rake task not reliable bit worrying least.

has encounter such problem before? ideas how proceed further?

all dynamic methods except find_by_... , find_by_...! deprecated.

all methods have xxx_by_ xxx_by (remove underline on end-method). so, can use:

  • find_by... , find_by...! or
  • where(...).to_a returns array or where(...).last return object

note where(...) returns relation, not array.

http://guides.rubyonrails.org/upgrading_ruby_on_rails.html


Comments