Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.2 ActiveAdmin 'Collection is not a paginated scope.' error

I'm developing an application using Rails 3.2 and ActiveAdmin 0.4.4. I have model named Teaser (/app/models/teaser.rb):

class Teaser < ActiveRecord::Base
  attr_accessible :img, :name, :url
  validates :img, :name, :presence => true
  mount_uploader :img, TeaserUploader
end

And I added ActiveAdmin to it (/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

Now, when I go to 'http://localhost:3000/admin/teasers', I get the following error:

Showing C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.4/app/views/active_admin/resource/index.html.arb where line #1 raised: Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.

I get the same error when I test my app on linux (Ubuntu 12.04).

I can solve this problem by this way (/app/admin/teaser.rb):

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

But if I use this method, I cannot translate this model by using /app/config/locales/XX.yml

All other models work properly.

like image 323
Ivan Larionov Avatar asked Aug 20 '12 07:08

Ivan Larionov


4 Answers

In some cases all you need to do is change the model's label in active admin

Example

BREAKS

ActiveAdmin.register Stage do

WORKS

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

The same case is for a model Page

Update: 30-May

I've run into this issue again, with a model like

ActiveAdmin.register PageRedirects do

and in the application_controller.rb I had this:

before_filter :abc

def abc
  @page_redirects = ...
end

This method overrides the @page_redirects from the active-admin controller I guess.

like image 53
vladCovaliov Avatar answered Nov 20 '22 03:11

vladCovaliov


Here is the solution (/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
like image 35
Ivan Larionov Avatar answered Nov 20 '22 03:11

Ivan Larionov


You may have a variable with the same name as the controller that is conflicting. Maybe in your application_controller.rb?

like image 4
m1mike Avatar answered Nov 20 '22 03:11

m1mike


Just improving the answer... I had problems when using the active admin filters, so I had to modify a little bit the code. Its working for me now.

collection_action :index, :method => :get do
  scope = Teaser.scoped
  @search = scope.metasearch(clean_search_params(params[:q]))
  @collection =  @search.page()  
end
like image 2
Flavio Alves Avatar answered Nov 20 '22 04:11

Flavio Alves