This question must have been asked already, but I can't find it.
I have a UsersController
and an Admin::UsersController
. Obviously a lot of what goes on in these classes (eg the implementation of strong_parameters
, the paths to follow after creating/editing a user) are the same.
Can I - indeed, ought I? - share code between these controllers? Is this what concerns are for? The examples I find for them online tend to deal with models.
Any guidance much 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With