Reputation: 176
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.
Upvotes: 8
Views: 4975
Reputation: 1942
Adding a default scope in active admin solved the issue for me.
ActiveAdmin.register StaticPage, as: 'Static Page' do
scope :all, default: true
# ...
end
Upvotes: 0
Reputation: 793
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.
Upvotes: 0
Reputation: 4403
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.
Upvotes: 10
Reputation: 6281
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.
Upvotes: 1
Reputation: 51
You may have a variable with the same name as the controller that is conflicting. Maybe in your application_controller.rb?
Upvotes: 4
Reputation: 33
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
Upvotes: 2
Reputation: 176
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
Upvotes: 5