user3465903
user3465903

Reputation: 3

Rails ".where()" clause with decimal division

I'm trying to run something like this:

@almostFullTopics = Topic.where("(user_submissions_count/submissions_cap) >= .8 ")

where user_submissions_count and submissions_cap are both whole numbers. This doesn't work at the moment because the division is not done properly. I essentially need something like this:

@almostFullTopics = Topic.where("(user_submissions_count.to_f/submissions_cap) >= .8 ")

Any ideas on how I can go about implementing this?

Upvotes: 0

Views: 263

Answers (1)

Edward
Edward

Reputation: 3499

As in this answer, Division in a SQL statement. it might be worth approaching this in a different direction.

@almostFullTopics = Topic.where("user_submissions_count  >= 0.8 * submissions_cap") 

Upvotes: 1

Related Questions