Here is what I’m trying to do:
I have a rail model, let’s call it Item. In the db I have a list of items. Therefore I can do a
item = Item.find(28)
and get an object representing the item found in the database.
Now, I also have another Model, let’s say Order that needs to do a validate_inclusion_of for one of its fields, to see if the item name is in the Item database.
Something like
validates: item_name, :presence => true
:inclusion => Item.all.name #get an array of all possible item names
Can this be done? What would be the nicest way of doing that?
Best Regards,
O.
Try this:
UPDATE
this is a the full implementation:
now in your order model:
now we need to test this in console
and in console