1

So i have a controller which subclasses down from the application controller. It defines a variety of protected methods, as well does the application controller. Now, if the application controller already defines those methods, I do not want them to be overwritten by its subclass. I've been trying things in this controller such as:

class SomeController < ApplicationController

protected
  unless instance_methods.include? "some_method"
    def some_method
    end
  end

However, using the Rails logger, I can still see that the some_method is being called.

agmcleod
  • 13,321
  • 13
  • 57
  • 96
  • I don't understand your question. You know which methods you have in your `ApplicationController`, right? So don't define those in your subclass. Or am I missing something? – Mischa Oct 12 '12 at 19:16
  • 1
    To elaborate, this SomeController is part of a Rails engine that we also use in some cases as a standalone app. So if it's standalone, it inherits from actioncontroller, and defines the methods. If it's an engine, it inherits from the parent's application controller. Since the parent's app methods here are correct for its purpose, I need to not overwrite those in the engine, as it causes us some issues :) – agmcleod Oct 12 '12 at 19:18

1 Answers1

0

Doing some further searching, I was able to figure it out :), thanks to the poster on this question here: How to judge whether a method has defined in a class?

class SomeController < ApplicationController

protected
  unless method_defined? "some_method"
    def some_method
    end
  end
Community
  • 1
  • 1
agmcleod
  • 13,321
  • 13
  • 57
  • 96