Rails 3.2 ActiveAdmin’集合不是分页范围。’ 错误

我正在使用Rails 3.2和ActiveAdmin 0.4.4开发一个应用程序。 我的模型名为Teaser(/app/models/teaser.rb):

class Teaser  true mount_uploader :img, TeaserUploader end 

我添加了ActiveAdmin(/app/admin/teaser.rb):

 # encoding: UTF-8 ActiveAdmin.register Teaser do form do |f| f.inputs "Teaser" do f.input :name, :label => 'Текст' f.input :url, :label => 'Ссылка' f.input :img, :as => :file, :label => 'Картинка' end f.buttons end end 

现在,当我去’http:// localhost:3000 / admin / teasers’时,我收到以下错误:

显示C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/app/views/active_admin/resource/index.html.arb第1行引发:收集不是分页范围。 在调用之前设置collection.page(params [:page])。per(10):paginated_collection。

当我在linux上测试我的应用程序时,我得到了同样的错误(Ubuntu 12.04)。

我可以通过这种方式解决这个问题(/app/admin/teaser.rb):

 # encoding: UTF-8 ActiveAdmin.register Teaser, :as => 'Somename' do 

但是如果我使用这种方法,我就无法使用/app/config/locales/XX.yml来翻译这个模型

所有其他模型都正常工作。

在某些情况下,您需要做的就是在活动管理员中更改模型的标签

BREAKS

 ActiveAdmin.register Stage do 

作品

 ActiveAdmin.register Stage, as: "Opportunity Stage" do 

同样的情况是模型页面

更新:5月30日

我再次遇到这个问题,模型就像

ActiveAdmin.register PageRedirects做

application_controller.rb我有这个:

 before_filter :abc def abc @page_redirects = ... end 

我想这个方法会覆盖来自active-admin控制器的@page_redirects。

这是解决方案(/app/models/teaser.rb)

 collection_action :index, :method => :get do scope = Teaser.scoped @collection = scope.page() if params[:q].blank? @search = scope.metasearch(clean_search_params(params[:q])) end 

只是改进答案……我在使用主动管理filter时遇到了问题,所以我不得不修改一点代码。 它现在为我工作。

 collection_action :index, :method => :get do scope = Teaser.scoped @search = scope.metasearch(clean_search_params(params[:q])) @collection = @search.page() end 

您可能有一个与冲突控制器同名的变量。 也许在你的application_controller.rb中?

在rails 4.1中,没有一个答案对我有用

在github问题的讨论中发现,这是由活动管理员从应用程序控制器inheritance的事实引起的。
所以为了回答这个问题,我想这个错误是由于在应用程序控制器中为@teasers分配一些集合引起的。

你能否请在活动管理页面上重命名资源名称

 ActiveAdmin.register Teaser, as: "Some other name" do 

这解决了我的问题。

我认为这是由于资源名称冲突造成的。

在活动管理员中添加默认范围为我解决了这个问题。

 ActiveAdmin.register StaticPage, as: 'Static Page' do scope :all, default: true # ... end