I have an Assignment class which belongs to both a User class and a Role class. It stores three values – a reference to the User it belongs to, a reference to the Role it belongs to, and a string value indicating the name of the User who create the Assignment instance.
class Assignment < ActiveRecord::Base
include ActiveModel::Validations
belongs_to :user
belongs_to :role
attr_accessible :user, :role, :assigned_by_user
...
In my model validation, I would like to perform a check to make sure that the assigned_by_user attribute does match the name of a valid user. However, I can’t seem to access the User.find(…) method within the Assignment model.
How would I achieve this functionality?
Add a “Check User” module to your lib folder (check_user.rb). Then in that file
Then in your Assignment model