سؤال

My new controller action:

controller do
  layout 'active_admin'
  def index
    @pages = Page.all
  end
end

After refresh the page i received:

undefined method `base' for nil:NilClass 
render view_factory.layout

What should I do for fixing this?

I start rewriting controller action because i received this message for my index action:

undefined method `num_pages' for #<Array:0x0000000b860eb0>
render renderer_for(:index)

Maybe anyone know how fixing this?

هل كانت مفيدة؟

المحلول

The initial undefined method 'num_pages' for #<Array:0x0000000b860eb0> may be occurring if you have an instance variable set in a before_filter in ApplicationController with the plural name of a model as I did. The bug is reported here.

نصائح أخرى

Would need to see the code on the view page for this but it sounds to me like you are making a call for num_pages on an object that is an array class. Since Ruby's array class has no num_pages method, it is throwing an error.

Jamie you are right! But then i received this message for my index action:

undefined local variable or method `per' for ActiveRecord::Relation

And I fix this problem by doing this:

# config/initializers/will_paginate.rb
if defined?(WillPaginate)
  module WillPaginate
    module ActiveRecord
      module RelationMethods
        alias_method :per, :per_page
        alias_method :num_pages, :total_pages
      end
    end
  end
end

The bug is reported here.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top