Monkey patching a gem (rails_admin, with Rails 3)

313 views
Skip to first unread message

Michel Pigassou

unread,
Jul 6, 2011, 11:40:50 AM7/6/11
to rubyonra...@googlegroups.com
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.

Frederick Cheung

unread,
Jul 6, 2011, 3:23:08 PM7/6/11
to Ruby on Rails: Talk


On Jul 6, 4:40 pm, Michel Pigassou <dag...@gmail.com> 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

Michel Pigassou

unread,
Jul 7, 2011, 3:55:32 AM7/7/11
to rubyonra...@googlegroups.com
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.

Conrad Taylor

unread,
Jul 7, 2011, 4:36:49 AM7/7/11
to rubyonra...@googlegroups.com
What are you trying to do exactly?

-Conrad 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/R-GP-E-bR8wJ.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Michel Pigassou

unread,
Jul 7, 2011, 5:40:56 AM7/7/11
to rubyonra...@googlegroups.com
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.

Michel Pigassou

unread,
Jul 7, 2011, 7:21:26 AM7/7/11
to rubyonra...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages