Skip to content

Instantly share code, notes, and snippets.

@jeffsaracco
Created June 19, 2013 17:45
Show Gist options
  • Save jeffsaracco/5816289 to your computer and use it in GitHub Desktop.
Save jeffsaracco/5816289 to your computer and use it in GitHub Desktop.
Remove the effects of FriendlyId in ActiveAdmin

Even better you could create a before filter in the base Active Admin controller ActiveAdmin::ResourceController so that it is automatically inherited into all your Active Admin controllers.

First add the filter to the config/initializers/active_admin.rb setup:

ActiveAdmin.setup do |config|
  # ...
  config.before_filter :revert_friendly_id
end

The open up ActiveAdmin::ResourceController and add a revert_friendly_id method, E.g. by adding the following to the end of config/initializers/active_admin.rb:

ActiveAdmin::ResourceController.class_eval do
  protected

  def revert_friendly_id
    model_name = self.class.name.match(/::(.*)Controller$/)[1].singularize

    # Will throw a NameError if the class does not exist
    Module.const_get model_name

    eval(model_name).class_eval do
      def to_param
        id.to_s
      end
    end
  rescue NameError
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment