Duplicate method in application_controller and application_helper

I have a method:

def current_practice
if session[:impersonating]
Practice.find session[:impersonating]
else
current_user.practice
end
end

It is identical in both controller and helper. How could I DRY this up
so I only need maintain it in one place?

I already have the line

helper:all

at the top of my ApplicationController, but when I commented out the
current_practice in the controller, the one from the helper didn’t
step in. Maybe I’m misunderstanding what that line is meant to do.

Walter

Never mind, found helper_method. So now I have
helper_method :current_practice in my ApplicationController, and it
magically appears in the ApplicationHelper as well.

Walter

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs