Good day to all!

Surely, you're familiar with such a cool thing in Rails as Layouts. If an application should have a single interface, then one such Layout a is enough а - application.html`, which, in fact, is used by default if there is nothing else, and the configuration remains unchanged. But if you use the familiar Ruby constructor in controllers:

 def initialize ... end 

This layout is not used. Actually, why so?

Thank)

  • The answer is completely offhand - and did you try to write initial initialization inside? - Stanislav Pankevich

1 answer 1

Sorry, weaned already from Ruby. I mean the following:

 class Parent def initialize puts "Parent" end end class Child < Parent def initialize super end end puts Child.new 

I assume that in Rails, as it is there, the ActionController in its initialize just sets the layout and therefore I suggest you check it out: just write

 def initialize super # А здесь код, который вы хотите исполнить в своём конкретном контроллере end 
  • Yes, that's right, the problem is this. For some reason I did not even suggest that part of the functional may be in the constructor (initializer) of the parent class. Your answer helped me, so thank you very much) - AseN
  • You are welcome! Good luck! - Stanislav Pankevich