2014-11-06 82 views
2

我有一個奇怪的問題,我ActiveAdmin資源:軌道4 ActiveAdmin - 未定義的局部變量或方法`collection_before_scope」

ActiveAdmin.register ServicePage do 
    menu priority: 5 

    permit_params :title, :body, :slug, :published 

    config.sort_order = 'created_at_desc' 
    config.per_page = 10 

    scope :all, default: true 
    scope :published 
    scope :not_published 

    filter :title 
    filter :slug 
end 

當我嘗試訪問索引頁吧,我得到undefined local variable or method 'collection_before_scope' for #<ActiveAdmin::Views::Scopes:0x007f4c8ecdfa28>錯誤。

當我刪除那些3 scope的,我得到Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.

但是,如果只有我更改代碼ActiveAdmin.register ServicePage, as: 'page' do,一切似乎變得確定。我確信,當我剛剛將ServicePage資源添加到ActiveAdmin時,它工作正常。有人可以告訴我,發生了什麼事?

(紅寶石2.1.2,4.1.6的Rails,active_admin 1.0.0.pre)

回答

0

的問題是在我的ApplicationController中,在此代碼:

class ApplicationController < ActionController::Base 
    before_action :set_service_pages 

    # ... 

    def set_service_pages 
    @service_pages = ServicePage.published 
    end 
end 

如果我改變@service_pages變量名稱,都開始再次工作。所以我的解決方案是在我的ActiveAdmin的ServicePage資源中添加

controller do 
    skip_before_filter :set_service_pages 
end 

順便說一句,爲什麼ActiveAdmin甚至關心我的變量名?

+0

ActiveAdmin(繼承的資源)會自動實例化與您的資源相對應的變量,這可能會導致像這樣的衝突。 – 2017-07-12 00:02:09

相關問題