Reputation: 467
I use devise with custom controller (user controller). Rather than logging in and going to user/edit
, I prefer to serve the home page. To do so, I need to edit the devise session create controller method.
I know I can edit the devise custom controller by following the instructions devise provides:
# before_action :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
# def create
# super
# end
# DELETE /resource/sign_out
# def destroy
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
# end
So following those instructions, how do I simply have the create
method do exactly what it currently does, but redirect_to "/"
rather than what it's currently doing?
Note here's what it's currently doing:
self.resource = resource_class.new(sign_in_params)
clean_up_passwords(resource)
yield resource if block_given?
respond_with(resource, serialize_options(resource))
Also note, I could copy that code directly from devise on github, then edit it, like so:
self.resource = resource_class.new(sign_in_params)
clean_up_passwords(resource)
yield resource if block_given?
redirect to: "/"
but I want to do this using the super
method as that's what's recommended in the devise instructions.
Upvotes: 0
Views: 112
Reputation: 526
No need to redefine create
action, as Devise allows you to do just that with after_sign_in_path_for
method.
def after_sign_in_path_for(resource)
root_path
end
Upvotes: 2