Monkey patching a gem (rails_admin, with Rails 3)

Hi.

I’m trying to monkey patch the rails_admin gem.

First, I tried to add a file in config/initializers containing:
RailsAdmin::MainController.class_eval do
def get_sort_hash
CODE HERE…
end
end

It was only loaded once, and then the method from the gem was always
executed instead of mine.

I also tried to add the code in lib/ with the correct line in
config/application.rb to load all files in lib/. But in this case it
does
not work at all.

Each time I defined my method using the following blocks:
RailsAdmin::MainController.class_eval do end
::RailsAdmin::MainController.class_eval do end

Any idea? Thanks.

You’re probably right, but I would not lose rails_admin features.

But as nobody answered my problem on the plugin’s mailing list I think
I’m
gonna try other backend tools.

On Jul 6, 4:40pm, Michel P. [email protected] wrote:

Hi.

I’m trying to monkey patch the rails_admin gem.

Not entirely answering the question, but why not just fork it on
github? Bundler makes it super easy to install gems from your own git
repo

Fred

On Wed, Jul 6, 2011 at 8:40 AM, Michel P. [email protected]
wrote:

Any idea? Thanks.

What are you trying to do exactly?

-Conrad

I want to be able to sort a view of a model that has nested belongs to:
Checkin belongs to a Program that belongs to a User
So I want to sort the checkins according to the linked users.

OMG I feel ashame, I discovered that what I want to do at the
relationship
level can be done with a has_one :through… Never thought of using
this!

BTW I modified the admin_data plugin to tweak the sorting order and add
scopes, could be useful for other nested associations.