Skip to content

Commit

Permalink
#2537: autoload the comments model
Browse files Browse the repository at this point in the history
By not loading the Comments model until Rails is initialized, we can
rely on the user's changes to Kaminari settings.

This is a backport of 3d23682 from master to 0-6-stable
  • Loading branch information
seanlinsley committed Dec 30, 2013
1 parent fa0edec commit 77c97d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/active_admin/comments.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'active_admin/comments/comment'
require 'active_admin/comments/views'
require 'active_admin/comments/show_page_helper'
require 'active_admin/comments/namespace_helper'
Expand All @@ -18,6 +17,11 @@
# Add the module to the show page
ActiveAdmin.application.view_factory.show_page.send :include, ActiveAdmin::Comments::ShowPageHelper

# Load the model as soon as it's referenced. By that point, Rails & Kaminari will be ready
module ActiveAdmin
autoload :Comment, 'active_admin/comments/comment'
end

# Walk through all the loaded resources after they are loaded
ActiveAdmin.after_load do |app|
app.namespaces.values.each do |namespace|
Expand Down
7 changes: 1 addition & 6 deletions lib/active_admin/comments/comment.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
require 'kaminari/models/active_record_extension'

module ActiveAdmin

# manually initialize kaminari for this model
::ActiveRecord::Base.send :include, Kaminari::ActiveRecordExtension

class Comment < ActiveRecord::Base

belongs_to :resource, :polymorphic => true
belongs_to :author, :polymorphic => true

Expand Down

0 comments on commit 77c97d2

Please sign in to comment.