Walter Lee Davis
2011-May-11 18:34 UTC
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Davis
2011-May-11 19:02 UTC
Re: Duplicate method in application_controller and application_helper
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 On May 11, 2011, at 2:34 PM, Walter Lee Davis wrote:> 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 > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.