Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
917 views
in Technique[技术] by (71.8m points)

scope - How do I show unscoped models in Rails Admin?

I needed this myself, so here it is QA-style:

By default, Rails Admin shows a model's default_scope. How do I get it to show every model completely unscoped?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Approach 1

If you only need to list the records you can use the scopes method to control which records are returned. The first array element is the default, so if you add the following to your initialiser:

list do
  scopes [:unscoped]
end

you will see all records.

Approach 2

If you want to do more than list models you can create a dummy rails admin model. For example, assuming you have a Post model with a boolean archived flag:

class Post < ActiveRecord::Base
  default_scope { archived: false }
end

You can create a dummy model to use in rails_admin like so (in app/models/rails_admin)

class RailsAdmin::Post < ActiveRecord::Base
  self.table_name = "posts"
end

You then configure rails_admin to use RailsAdmin::Post and all of the Posts will be unscoped.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...