I investigated the super that I met with the devise controller

Introduction

I'm using devise for user management. When I was playing with the controller, there was a method with only super in the method, so I was wondering and examined it.

devise controller

rails g devise:controllers user

Is generating a controller.

user/registrations_controller.rb


class Users::RegistrationsController < Devise::RegistrationsController
(Omitted)
  def update
    super
  end
(Omitted)
end

Apparently, it inherits from the Devise :: RegistrationsController class. There is a super in some methods.

What is super

All in all, super is a method that can call the inherited method . Taking the above controller as an example, The update method is also described in Devise :: RegistrationsController, This means that you can do the same with Users :: RegistrationsController.

In another example ...

The following are the explanations I often see during my research.

class Tennis
  def ball
    puts "Tennisball"
  end
end

class Sports < Tennis
  def ball
    super
    puts "balls"
  end
end

sports = Sports.new
sports.ball
#=>Tennisball
sports = Sports.new
sports.ball
#=>balls

If I made it myself as an analogy, it would be meaningless code ... The point is that even if you create a method with the same name after inheritance, you can use super to call the process before overriding.

Recommended Posts

I investigated the super that I met with the devise controller
I touched the devise controller that I felt in the black box
I investigated the enclosing instance.
I investigated the mechanism of attr_accessor (* Hoge :: ATTRIBUTES) that I sometimes see
I checked the library "junit-quickcheck" that can perform property-based testing with JUnit
[Swift] I investigated the variable expansion "\ ()" that realizes the mysterious function of Swift UI.
I investigated the internal processing of Retrofit
I tried to summarize again the devise that was difficult at first sight
I rewrote the Rails tutorial test with RSpec
I don't see the flash message with redirect_to
[NCMB] I searched the data store with mbaas
Understanding the MVC framework with server-side Java 3/4 Controller
I checked the number of taxis with Ruby