accessing devise current_user within model
问题 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 model def opponent_name=(name) self.opponent = Opponent.find_or_create_by_name_and_team_id(name,current_user.team_id) if name.present? end but the error i am getting is NameError in EventsController#create undefined local variable or method `current_user' for #<Event:0x007fb575e92000> 回答1: current_user is not accessible from