Permit configuration within the model classes. #275

Closed
yfeldblum opened this Issue Feb 4, 2011 · 3 comments

Comments

Projects
None yet
3 participants

Feature idea: Permit configuration of each model class to be embedded within the model classes.

In addition to:

# config/initializers/rails_admin.rb
RailsAdmin.config do |config|
  config.model Team do
    list do
      items_per_page 100
    end
  end
end

Also permit:

# app/models/team.rb
class Team < ActiveRecord::Base
  has_many :players
  # ...
  rails_admin do
    list do
      items_per_page 100
    end
  end
end

And even permit:

# config/initializers/rails_admin.rb
Team.rails_admin do
  list do
    items_per_page 100
  end
end
Owner

sferik commented Mar 29, 2011

I really like example 2. I think it makes a lot of sense to include the model's admin configuration in the model itself.

Not sure how I feel about the last example, but it seems at least as good (if not better) than what we have now.

@kaapa: I'd be curious to get your thoughts on any implementation challenges associated with this.

Collaborator

kaapa commented Mar 29, 2011

I guess we could simply define method rails_admin in ActiveRecord::Base which would just proxy to RailsAdmin::Config.model(self).

Models classes being managed by RailsAdmin will no longer be eager-loaded automatically in development (using the model class constants in the RailsAdmin initializer loads the model classes). Instead, RailsAdmin will have to load them all explicitly. RailsAdmin's initializer should take care to clear and reload the model classes' configurations cache (to clear out the prior request's configuration) on, if classes are cached, initialization, and, if classes are not cached (in development) on every request that makes it to ActionDispatch.

Cheers!

@kaapa kaapa closed this in d035100 Jul 4, 2011

bbenezech added a commit that referenced this issue Jul 4, 2011

bbenezech added a commit that referenced this issue Jul 4, 2011

bbenezech added a commit that referenced this issue Jul 4, 2011

mshibuya added a commit to mshibuya/rails_admin that referenced this issue Aug 17, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment