Given that I have a class A that is abstract and encapsulates the logic that is needed in the decands of B and C.
class A end class B < A end class C < A end
In addition, if there is a resourceful routing that provides routes for B and C and therefore is handled by the respective controllers.
To dry things, I moved the common code of both conntrollers to an "abstract" controller (it was never created or directed to its actions):
class AController < ApplicationController def new(additional_opts) render locals: {base: "stuff"}.merge(additional_opts) end end class BController < AController def new super(foo: 1) end end class CController < AController def new super(bar: 1) end end
A controller action usually has no parameters. But since the ACcontroller needs to be abstract, can this approach be valid or better rely on instance variables and just call super and then pull the right information from the variables instead?
Any ideas are welcome.
Change 1:
Fortunately, Lateralu42 suggested problems that make me think; ok, what is my real question, here i want to have anders (As in the hitch hikers guide). So what is also about using that code reuse method?
Found a nice blog post here .
source share