Topic: How to use a parent class method with same name

Hi, I have a controller class which extends a cms controller.

I'd like to add some extra functionality to the "destroy" method in the child controller class (delete associated files as well).

I'm aiming for something like this:

  def destroy
    # remove associated files
    ...
    # perform destroy method from parent controller
    Admin::CmsController.destroy
  end

But I get this error:
undefined method `destroy' for Admin::CmsController:Class

(it's definitely defined, confirmed by "raise Admin::CmsController.public_instance_methods(false).inspect")

I'm tempted to just paste the code from the parent controller there (it's only a few lines) but I'd really like to know the DRY way of achieving this. Anyone know? Thanks

Zubin

Re: How to use a parent class method with same name

that's really strange.  Can you post the full code for all the classes involved?

Re: How to use a parent class method with same name

Thanks Danger, here it is (snipped for clarity). I suspect it may have something to do with these methods in CmsController: this_controller, this_model

class Admin::CmsController < ApplicationController
  def destroy
    if (@obj = this_model.find(params[:id])).destroy
      flash_success
    else
      flash_errors
    end
    redirect_to :action => "index"
  end

  private

  def this_controller
    self.controller_name
  end

  def this_model
    this_controller.singularize.camelize.constantize
  end
end


class Admin::IssuesController < Admin::CmsController
  def destroy
    Admin::CmsController.destroy
    issue = Issue.find(params[:id])
    rm_path = "#{RAILS_ROOT}/public/images/issues/#{issue.volume}/#{issue.issue_number}"
    FileUtils.rm_rf(rm_path)
    redirect_to :action => "index"
  end
end

Zubin