hi i am trying to access current_user within a model for the purpose of creating an element on the fly with find_or_create_by.
the following is the method within my mode
current_user
is not accessible from within model files in Rails, only controllers, views and helpers.
What you should do is to pass the current_user.team_id
to the opponent_name
method like this:
def opponent_name=(name, current_user_team_id)
self.opponent = Opponent.find_or_create_by_name_and_team_id(name,current_user.team_id) if name.present?
end