8

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.

7 Answers 7

10

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.

0
5

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
2
  • Same problem here. My admin page was working well and suddenly Boom! Your piece of code has solved the problem...
    – fro_oo
    Feb 15, 2013 at 14:40
  • page needs an argument, do you use params[:page]?
    – sites
    Oct 6, 2015 at 20:00
4

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

1
  • is clear and an excellent point, thanks, i do have variables with the same name in mi application controller, i rename those and everything works fine, thanks
    – Alexis
    Mar 27, 2015 at 7:08
2

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
1

None of the answers worked for me in rails 4.1

In the discussion at the github issue it turns out that this is caused by the fact that active admin is inheriting from the application controller.
So to answer this question, I suppose the bug is caused by assigning some collection to @teasers in the application controller.

0

Can you please rename resource name on active admin page like

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

This solved my issue.

I think this is due to conflict of resource name.

0

Adding a default scope in active admin solved the issue for me.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.