gpt4 book ai didi

ruby-on-rails - Admin :Class --- CanCan 的未定义方法 `find'

转载 作者:行者123 更新时间:2023-12-01 23:35:14 25 4
gpt4 key购买 nike

有没有人看到这个错误:

undefined method `find' for Admin:Class

什么时候使用 Devise 和 CanCan?

我无法确定这是错误的地方:日志显示没有任何用处:
Started GET "/admin/become?id=3" for 127.0.0.1 at Wed Apr 06 13:09:15 -0700 2011
SQL (0.3ms) SHOW client_min_messages
SQL (0.2ms) SET client_min_messages TO 'panic'
SQL (0.5ms) SET standard_conforming_strings = on
SQL (0.2ms) SET client_min_messages TO 'notice'
SQL (0.4ms) SET time zone 'UTC'
SQL (0.1ms) SHOW TIME ZONE
Processing by AdminController#become as HTML
Parameters: {"id"=>"3"}
User Load (2.2ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 2) LIMIT 1
Completed in 57ms

NoMethodError (undefined method `find' for Admin:Class):


Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms)
Permission Load (2.5ms) SELECT * FROM "permissions" INNER JOIN "groups" ON "groups"."id" = "permissions"."group_id" WHERE ("permissions"."user_id" = 2) ORDER BY groups.name ASC
SQL (1.3ms) SELECT COUNT(*)
FROM pg_tables
WHERE tablename = 'groups'

应用程序跟踪:
cancan (1.5.1) lib/cancan/controller_resource.rb:102:in `find_resource'
cancan (1.5.1) lib/cancan/controller_resource.rb:67:in `load_resource_instance'
cancan (1.5.1) lib/cancan/controller_resource.rb:31:in `load_resource'
cancan (1.5.1) lib/cancan/controller_resource.rb:24:in `load_and_authorize_resource'
cancan (1.5.1) lib/cancan/controller_resource.rb:9:in `send'
cancan (1.5.1) lib/cancan/controller_resource.rb:9:in `_callback_before_35483'
activesupport (3.0.3) lib/active_support/callbacks.rb:456:in `_run__22524425__process_action__2106917469__callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in `send'
activesupport (3.0.3) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `send'
activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'

最佳答案

背景:请参阅问题中的上述评论,包括 previous question , 和 this link详情。

您的问题源于没有基于设计的 Admin 类。我从 NoMethodFound 错误中收集了这些信息。这意味着您无法在其上使用任何类型的 ActiveRecord 方法,而基本实现正在尝试这样做。您可能想要替换这行代码...

return unless current_user.is_an_admin?

像这样的东西......
return unless current_user.admin == true

(或可以在您的用户模型表中找到的内容)

关于ruby-on-rails - Admin :Class --- CanCan 的未定义方法 `find',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5572415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com