I have an application that has users whose profiles are accessible through site.com/username. Choosing a username, I make an AJAX call to a method in my UserController to make sure the username is available (and also check, like at the end, when it is sent). Now I want to add groups that will also be available through site.com/groupname. Since group and user names cannot collide, any controller method that answers an AJAX call will have to check both options, so the check_username_available and check_groupname_available methods will do the same. What is the best practice / Rails way to handle this since I don't want to replicate the code in both UserController and GroupController?
Having a method for each controller seems a little redundant, even if the functionality is displayed to the assistant, since there will still be two routes that do the same. Having a separate controller also solves the problem, but I'm not sure if this is a good Rails practice.
source share