Rails Active Admin 资源问题

发布于 2024-12-06 18:54:11 字数 505 浏览 8 评论 0原文

我最近观看了关于主动管理的railscast 284,并想将其实现到我的网络应用程序中,但是当我添加资源时遇到了问题。每次尝试导航到创建的选项卡时,我都会收到以下消息:

NameError in Admin::LoadsController#index

undefined local variable or method `per' for []:ActiveRecord::Relation
Rails.root: /Users/thomascioppettini/rails_projects/want-freight

Application Trace | Framework Trace | Full Trace
Request

Parameters:

{"order"=>"id_desc"}
Show session dump

Show env dump

Response

Headers:

我能想到的唯一可能影响应用程序的事情是添加一个验证码来设计,这是活动管理所依赖的。

I recently have watched railscast 284 about active admin and wanted to implement it into my web app, however I am running into an issue when I add a resource. I get the following message every time I try to navigate to the created tab:

NameError in Admin::LoadsController#index

undefined local variable or method `per' for []:ActiveRecord::Relation
Rails.root: /Users/thomascioppettini/rails_projects/want-freight

Application Trace | Framework Trace | Full Trace
Request

Parameters:

{"order"=>"id_desc"}
Show session dump

Show env dump

Response

Headers:

None

The only thing I can think of that may affect the application is adding a recaptcha to devise, which active admin depends on.

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

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

发布评论

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

评论(4

沐歌 2024-12-13 18:54:11

对我来说,这看起来像是一个分页问题。你用的是什么宝石?您应该提供有关您的设置的更多详细信息。您能向我们展示您的管理目录中的资源文件吗?您使用什么版本的 Rails 和 ActiveAdmin?

For me, it looks like this is a pagination problem. What gem are you using? You should give as more details about your settup. Can you show us your resource file from admin directory? What version of rails and what ActiveAdmin are you using ?

短暂陪伴 2024-12-13 18:54:11

如果您使用 will_paginate gem,请将版本设置为 3.0.pre2。我使用的是 ~>3.0.pre2,当我运行 bundle update 时,它会自动更新到 3.0.2 恢复修复了问题。如果您使用的是 Bundler,则该行是这样的:

gem "will_paginate", "3.0.pre2"

If you are using the will_paginate gem, set the version to 3.0.pre2. I was using ~>3.0.pre2, which auto-updated to 3.0.2 when I ran a bundle update Reverting fixed the issue. If you're using Bundler, the line is this:

gem "will_paginate", "3.0.pre2"
白况 2024-12-13 18:54:11

我同意达瓦伊德的观点。这是一个分页错误。将“Kaminari”宝石添加到您的 Gemfile 中。根据活动管理文档,它使用 kaminari 进行分页.. will_paginate 也将为您工作,正如 swilliams 所描述的那样...

I agree with Dawaid. It is a pagiantion error. Add "Kaminari" gem to you Gemfile. According to active admin docs, it is using kaminari for pagination.. will_paginate will also work for you as swilliams described...

听风吹 2024-12-13 18:54:11

据我了解 active_admin 不再支持 will_paginate 。但是,如果您不想将分页重写为 Kaminari,您可以通过将一些代码放入初始值设定项来解决此问题

# 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

module ActiveRecord
  class Relation
    alias_method :total_count, :count
  end
end

As I understand active_admin doesn't support will_paginate anymore. But if you don't want to rewrite your pagination to Kaminari you can fix this problem with putting some code to initializers

# 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

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