Undefined method “reorder” for # using ActiveAdmin

前端 未结 3 1717
南笙
南笙 2020-12-19 02:25

I have a problem with ActiveAdmin using Ruby ruby 1.9.2p290 and Ruby on Rails 3.2.1.

I used this wiki page to setup the resource for the AdminUsers that works perfec

相关标签:
3条回答
  • 2020-12-19 03:07

    The active admin make special processing of @resource variables. Where resource is correponding class name passed to register method. So for code:

    ActiveAdmin.register Project do  
    end
    

    name of variable is

    `@project`
    

    We must not assign value to variable with such name. Also such varibles may be object of ActiveRecord::Relation class. And how @Oliver write the name like @projects_all is good choice. The using of skip_before_filter is solve the problem too.

    One crafty thing need to check. The controller of resource may not have any filters. The controller of resource may not exists at all. What is the filter name to put to skip_before_filter? And where is such filters? The default application controller is used anyway. The filter may be installed at main application controller. The error message of this problem is not informative at all. So need to check application controller for installed filters too.

    0 讨论(0)
  • 2020-12-19 03:16

    Ah, I've found the solution. I don't know exactly why the error happened but I had to change my application_controller.

    In the application_controller I fetched all projects to @projects:

    before_filter :getActiveProjects
    
    protected
    
      def getActiveProjects
        @projects = Project.isactive.find(:all, :order => 'LOWER(name) asc')
      end
    

    That was confusing ActiveAdmin. After I changed that to

    before_filter :getActiveProjects
    
    protected
    
      def getActiveProjects
        @projects_all = Project.isactive.find(:all, :order => 'LOWER(name) asc')
      end
    

    and projects_controller index action to

    def index
      @projects = @projects_all
    end
    

    everything worked fine ;)

    0 讨论(0)
  • 2020-12-19 03:26

    An easier solution is to just skip the filter in the particular active admin controller:

    ActiveAdmin.register Project do  
        controller do
          skip_before_filter :getActiveProjects
        end
    end
    
    0 讨论(0)
提交回复
热议问题