So my question is how would you implement your handwritten Helpers based on the role of current user.
Would it be efficient to change the behaviour at request time? e.g. the Helper somehow figures out the role of user, and include the proper SubModule?
module ApplicationHelper
module LoggedInHelper
# Some functions
end
module GuestHelper
# The Same functions
end
# If User is Guest then include GuestHelper
# If User is LoggedIn then include LoggedInHelper
end
Is it efficient this way? is it rails way? I've got a whole bunch of function that act like this, and I don't want to wrap every single one of them in an if statement
def menu_actions
if current_user.nil?
# User is guest
{ "Log in" => link_to "Login", "/login" }
else
# User is Logged In
{ "Log out" => link_to "Logout", "/logout" }
end
end
Thank you for your time and thoughts.