覆盖控制器操作后,活动管理布局丢失

发布于 2024-12-19 16:30:44 字数 438 浏览 0 评论 0原文

我的新控制器操作:

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

刷新页面后我收到:

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

我应该做什么来解决这个问题?

我开始重写控制器操作,因为我收到了有关索引操作的消息:

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

也许有人知道如何解决此问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

A君 2024-12-26 16:30:44

如果您在 ApplicationControllerbefore_filter 中设置了实例变量,则可能会出现 #的初始未定义方法“num_pages” > 像我一样使用模型的复数名称。该错误已在此处报告。

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.

铁轨上的流浪者 2024-12-26 16:30:44

需要在视图页面上查看代码,但在我看来,您正在对 array 类的对象调用 num_pages 。由于 Ruby 的数组类没有 num_pages 方法,因此它会抛出错误。

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.

流云如水 2024-12-26 16:30:44

杰米你是对的!但后来我收到了这条关于我的索引操作的消息:

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

我通过这样做解决了这个问题:

# 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

报告了错误 这里

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文