I am using Mongoid in a Rails application. Let's said there is a model called Product
. Each product
document have some fields that the other document don't have. Here are 2 examples.
{name: "Product A", color: "Yellow", discount: "0.9"}
{name: "Product B", color: "Blue", size: "XXL"}
The field discount
or size
may changed from time to time. Assumed I have a form that let users to search by the field name (i.e. discount
) and value. How can I pass the variable that contains the field name to a Mongoid Criteria?
Thanks.