class Request
include Mongoid::Document
field :code, type: String
validates :code, :presence => true,
:inclusion => { :in => proc { Listing.all_codes } }
Using Mongoid, I am trying to validate the :code input on the submission form to make sure they are using a proper code that is already in the database. The listing model :code field is also named :code.
This is the error:
undefined method `all_codes' for Listing:Class
Any suggestions? What is the reference equivalent in Mongoid?
This is a ruby level error saying that you do not have a method looking like
The
self.part is important.You might have it implemented like
You might just want
Listing.allReally the bug is a disagreement in method name between your Request class and your Listing class.