Short answer, you can't (at least not easily). current_user is a controller method and therefore the model doesn't have access to it (Rails is all about Model-View-Controller separation, remember). There's been a fair amount of discussion on these lists about accessing the user from the model, including a few MVC-breaking workarounds. Quick google should dig them out.
Related topics
Topic | Replies | Views | Activity | |
---|---|---|---|---|
How can we access current_model (Devise:Here model can be User,Account etc.) method inside AR model? | 8 | 303 | January 26, 2018 | |
How to get current_user when I'm in model | 2 | 1696 | January 24, 2009 | |
Accessing controllers from models | 0 | 90 | September 1, 2007 | |
getting session/controller objects available in a Model ??? | 13 | 245 | September 8, 2006 | |
devise get current use in another controler | 2 | 145 | January 4, 2013 |