1

I'm passing a variable

numbers = ["one", "two", ["three", "four"], "five"]

to a query in my model: Modelname.where(number: numbers ) but I only get retrieved objects with number attr number value equal to: "one", "two", "five".

How to get the "three" and "four" object ?

1
  • This is how: numbers = ["one","two","three","four","five"]. Commented Jul 26, 2015 at 11:55

2 Answers 2

2

Use flatten

numbers = ["one","two",["three","four"],"five"]

some_variable = numbers.flatten
=> ["one", "two", "three", "four", "five"]

Modelname.where(number: some_variable)
Sign up to request clarification or add additional context in comments.

Comments

0

You can use Modelname.where(number: numbers.flatten )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.