accessing devise current_user within model

后端 未结 4 1619
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 16:03

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

4条回答
  •  星月不相逢
    2021-01-25 16:23

    Its not a good way to access the current_user in a model, this logic belongs to the controller. But if you realy cant find a workaround you should put it into a thread. But keep in mind this is not the way how it should be build.

    https://rails-bestpractices.com/posts/2010/08/23/fetch-current-user-in-models/

提交回复
热议问题