Rails: how should I share logic between controllers? -


this question must have been asked already, can't find it.

i have userscontroller , admin::userscontroller. lot of goes on in these classes (eg implementation of strong_parameters, paths follow after creating/editing user) same.

can - indeed, ought i? - share code between these controllers? concerns for? examples find them online tend deal models.

any guidance appreciated.

use concerns (put in app/controllers/concerns)

module userscontrollable   extend activesupport::concern    def new   end    def create   end    private   def user_params     # strong params implementation   end end  class userscontroller < applicationcontroller   include userscontrollable end  class admin::userscontroller < applicationcontroller   include userscontrollable end 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -