简体   繁体   中英

Ruby on Rails - Active Admin: Conflict with a Global Variable

On Rails 4 with the latest version of Active Admin (using Ransack). I have an Award model that I made available globally in my application_controller.rb:

  before_action :set_awards

  private
    def set_awards
      @awards = Award.all
    end

This is so I could have a global navigation dropdown listing all awards (on the public side). I think this is conflicting with Active Admin. When I went to the Awards index page, I got the following error message:

Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.

I am not sure what this means exactly but since this is the only model this happens to, I'm guessing it has something to do with my code in the app controller. I think my problem is similar to this question:

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

...I would prefer not to change the model's label and the metasearch code provided doesn't work because (I think) Active Admin now uses Ransack. Thanks for any help.

I have had the same problem and it was a variable name i was declaring at the application controller that was conflicting with the ActiveAdmin.

I have a model called Post and in my applicationController i had a method like this:

def load_posts
  @posts = Post.all
end

It returned me the error you mention, so i fixed it changing the variable name to:

def load_posts
  @post_list = Post.all
end

Hope it helps.

May be you overwrited a local variable @awards in ApplicationController, but Active Admins is inheriting from the application controller. Just rename your variable and it will run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM