I’m using Devise and it offers “current_user” method in helpers, so that I can use in views and controllers.
However now I’d like to access to the “current_user” method in the models. Here’s what I have in controllers now.
def create
set_email_address(params[:email_address])
Comment.new(params[:content], set_email_address)
# [snip]
end
private
def set_email_address(param_email)
if current_user
@email_address = current_user.email
else
@email_address = param_email
end
end
I would like to move the “set_email_address” to a model because I think that is a logic and should be handed in the model. I’m planning on hooking up this method with one of the Rails callbacks.
In all honesty, this answer pretty much sums it up. This doesn’t belong in Model logic at all. As the other answer also says though, you can and should pass the
current_uservalue from the controller if you’d like to use it inside your model.