byCoder
byCoder

Reputation: 9184

Access activerecord field in rails

In controller method i need to find some data, using like, so i write:

***
esupp = oo.cell(line,'N')
supplier = Supplier.where("SUP_BRAND like ?", "%#{esupp}%")
@aa = @art_concret.find{|item| item['ART_SUP_ID']==supplier.SUP_ID}
***

But i get error like

undefined method `SUP_ID' for #<ActiveRecord::Relation:0xa65048c>

When i tried to write Supplier.all all is good, bit i need like from sql. Supplier has data (see this in console), but when try to access field, get error

Upvotes: 0

Views: 86

Answers (1)

girasquid
girasquid

Reputation: 15506

supplier isn't the object you think it is - it's a list of things you got back. If you're expecting to only get one Supplier back, do this instead:

supplier = Supplier.where("SUP BRAND LIKE ?", "%#{esupp}%").first

Upvotes: 1

Related Questions