1

I am trying to query my database with a boolean type that is passed to me through the controller as a string. What Rails attempts to do is the following:

SELECT "orders".* FROM "orders" WHERE "orders"."complete" = ?  [["complete", "false"]]

This yields an empty array which should not be the case. Having tried manually retrieving records via the rails console, I come up with the same results. However substituting "false" for "f" solves the problem.

It is not an ideal solution to use "f" as a substitute because I am using emberjs and the boolean type in my frontend models which by default sends up "true" or "false"

Why wont ActiveRecord accept full booleans as string and how can I make it do so?

tomasbasham
  • 1,695
  • 2
  • 18
  • 37

1 Answers1

1

By the looks of it you can't really do this without a helper of some kind. See the selected answer here:

String "true" and "false" to boolean

Community
  • 1
  • 1
RichardAE
  • 2,945
  • 1
  • 17
  • 20
  • That was what I was afraid of. Thanks for the reply. I shall just intercept the boolean in the params hash and convert it before I make the query – tomasbasham Apr 08 '15 at 14:38