Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you only want friendly ID's in the front end and don't care about them inside Active Admin, you can revert the effects of the friendly_id gem for your Active Admin controllers.</p> <p>I don't know exactly how friendly_id overrides the <code>to_param</code> method, but if it's doing it the normal way, re-overriding it inside all of your Active Admin controllers should fix it, e.g.:</p> <pre><code>ActiveAdmin.register Foobar do before_filter do Foobar.class_eval do def to_param id.to_s end end end end </code></pre> <p>Even better you could create a before filter in the base Active Admin controller <code>ActiveAdmin::ResourceController</code> so that it is automatically inherited into all your Active Admin controllers.</p> <p>First add the filter to the <code>config/initializers/active_admin.rb</code> setup:</p> <pre><code>ActiveAdmin.setup do |config| # ... config.before_filter :revert_friendly_id end </code></pre> <p>The open up <code>ActiveAdmin::ResourceController</code> and add a <code>revert_friendly_id</code> method, E.g. by adding the following to the end of <code>config/initializers/active_admin.rb</code>:</p> <pre><code>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 </code></pre> <p><strong>Update:</strong> I just updated the last code example to handle controllers with no related model (e.g. the Active Admin Dashboard controller)</p> <p><strong>Update 2:</strong> I just tried using the above hack together with the friendly_id gem and it seems to work just fine :)</p> <p><strong>Update 3:</strong> Cleaned up the code to use the standard way of adding Active Admin before filters to the base controller</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload