7
votes

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

7 Answers

9
votes

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.

5
votes

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
4
votes

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

2
votes

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
votes

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
votes

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
votes

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

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