Created
October 22, 2013 08:54
-
-
Save kibenimatik/7097363 to your computer and use it in GitHub Desktop.
Revert overriding #to_param method defined in models for ActiveAdmin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveAdmin.setup do |config| | |
# ... | |
config.before_filter :revert_friendly_id, :if => -> { !devise_controller? && resource_controller? } | |
end | |
# override #to_param method defined in model in order to make AA generate | |
# routes like /admin/page/:id/edit | |
ActiveAdmin::BaseController.class_eval do | |
protected | |
def resource_controller? | |
self.class.superclass.name == "ActiveAdmin::ResourceController" | |
end | |
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