Access Devise's current_user in Model

烂漫一生 提交于 2019-12-18 14:14:28

问题


How do I go about accessing Devises 'current_user' object inside of a model? I want to automatically append the current users id to a record when they create something. I know that I can manually set the user_id inside of the controller but I feel it would be easier/cleaner if it was handled by the model.


回答1:


Essentially, this kind of logic doesn't belong in a Model, so you're best to pass current_user in through a function in the model or on creation. This answer sums it up.

I know, I know, that's not the answer you wanted. Unfortunately, it may be cleaner looking to you, but it adds overhead to your model that you really don't want.



来源:https://stackoverflow.com/questions/5545116/access-devises-current-user-in-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!