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.
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.
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
You may have a variable with the same name as the controller that is conflicting. Maybe in your application_controller.rb?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With