Nick Delaney
Nick Delaney

Reputation: 601

Scope with an array of items in Rails 4

I am trying to create a multi-select filter for listing products available by vendors. I have a scope in my vendor_offering's model

scope :by_vendor, -> (vendor_id) {where vendor_id: vendor_id}

How can I get the scope to allow an array of items like [1,2,3] and return items that vendors 1,2,3 have available?

Upvotes: 0

Views: 87

Answers (1)

Legendary
Legendary

Reputation: 2242

params[:vendor].split(',').map{ |n| n.to_i }

It gave you needs array with ids.

Upvotes: 1

Related Questions