This is happening in an Approval model. Approval has an attribute for :email. So saying self.email is calling an Object of the Approval class with its email attribute.enter code here
def associate_correct_user
new_user = User.find_or_create_by_email self.email do |u|
u.invite!
end
If I am creating a user here I need to pass two other attributes (first_name and last_name). Those attributes need to be pulled from another model Email, for which self.email as already been validated against.
this is what makes sense in my head:
def associate_correct_user
new_user = User.find_or_create_by_email self.email do |u|
user = Email.find_by_email(self.email)
u.first_name = user.first_name
u.last_name = user.last_name
u.invite!
end
This creates the user, but does not set the first_name and last_name attributes to this new user…
Show me the lines of your log/development.log when the user is created. May be first_name and last_name are protected attributes.
Here you have an example of find_or_create_by http://api.rubyonrails.org/classes/ActiveRecord/Base.html#label-Dynamic+attribute-based+finders
It uses a different syntax.