如何从用户控制器中删除设计用户 [英] How to delete devise user from users controller

查看:127
本文介绍了如何从用户控制器中删除设计用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从用户控制器中销毁用户?



我有一个用户资源定义在 routes.rb 以及 Users Controller

  def destroy 
@ user.destroy
head:no_content
end

然而,这会创建下面的错误:

 未定义的方法`handle_dependency'for#< ; ActiveRecord的::协会:: HasAndBelongsToManyAssociation:0x8839440> 

我正在尝试找到这个错误代表什么以及适当的修复。可能是什么原因?



用户模型

  class User< ; ActiveRecord :: Base 
resourcify

after_create:assign_default_role
rolify:before_add => :before_add_method
#包含默认设计模块。其他可用的是:
#:confirmable,:lockable,:timeoutable and:omniauthable
devise:database_authenticatable,:registerable,
:可恢复,可记忆,可追踪,可验证,
:confirmable,:omniauthable

has_many:场馆,依赖::destroy
has_many:from_user_chats,:foreign_key => 'from_user_id',:class_name => '聊天'
has_many:to_user_chats,:foreign_key => 'to_user_id',:class_name => '聊天'
has_one:uploaded_file,as::imageable,dependent::destroy
acceptance_nested_attributes_for:uploaded_file,:reject_if => proc {| attributes |属性[资产。空白?

def name
#{first_name}#{last_name}
end

def before_add_method(role)
#做某事
end

def assign_default_role
add_role:visitor
end

def self.from_omniauth(auth)
其中(auth。 slice(:provider,:uid))。first_or_create do | user |
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname
end
end

def self.new_with_session(params,session)
如果session [devise.user_attributes]
new(session [devise.user_attributes],without_protection:true)do | user |
user.attributes = params
user.valid?
end
else
super
end
end

def password_required?
超级&& provider.blank?
end

def update_with_password(params,* options)
如果encrypted_pa​​ssword.blank?
update_attributes(params,* options)
else
super
end
end

end

堆栈跟踪:

 已启动DELETE用户/ 6为127.0.0.1在2014-01-22 20:33:08 +1100 
处理用户控制器#销毁为HTML
参数:{authenticity_token=>T5pbLtoI0MAiaFW0x24LXdlospa4b8ogVtdLbhqEYyc =, id=>6}
[1m [36mUser Load(1.0ms)[0m [1mSELECTusers。* FROMusersWHEREusersid= 1 ORDER BYusers idASC LIMIT 1 [0m
[1m [35mUploadedFile Load(0.0ms)[0m SELECTuploaded_files。* FROMuploaded_filesWHEREuploaded_filesimageable_id= $ 1 ANDuploaded_files。 imageable_type= $ 2 ORDER BYuploaded_files。idASC LIMIT 1 [[imageable_id,1],[imageable_type,User]]
[1m [36mUser Load(0.0ms) 0m [1mSELECTusers。* FROMusersWHEREusers。id= $ 1 LIMIT 1 [0m [[id,6]]
[1m [35m(0.0ms) 0m SELECT COUNT(*)FROMrolesINNER JOINusers_rolesONroles。id=users_roles。role_idWHEREusers_roles。user_id= $ 1 AND(((roles.name ='admin')AND(roles.resource_type IS NULL) AND(roles.resource_id IS NULL)))[[user_id,1]]
[1m [36m(0.0ms)[0m [1mSELECT COUNT(*)FROMrolesINNER JOINusers_rolesON id=users_roles。id=users_roles。role_idWHEREusers_roles。user_id= $ 1 ANDroles。name='admin'[0m [[user_id,1]]
[1m [35mRole Load(0.0ms)[0m SELECTroles。* FROMrolesINNER JOINusers_rolesONroles。id=users_roles。role_idWHEREusers_rolesuser_id = $ 1 ANDroles。name='admin'[[user_id,1]]
[1m [36m(1.0ms)[0m [1mSELECTproductsidFROMproducts INNER JOIN角色ON角色.resource_type ='Product'AND
(roles.resource_id IS NULL ORroles.resource_id =products.id)WHERE(roles.name IN ('admin')ANDroles.resource_type ='Product')AND(roles.id IN(3)AND((resource_id =products.id)OR(r esource_id IS NULL)))[0m
[1m [35mCACHE(0.0ms)[0m SELECTusers。* FROMusersWHEREusers。id= $ 1 LIMIT 1 [[id 6]]
[1m [36mUploadedFile Load(0.0ms)[0m [1mSELECTuploaded_files。* FROMuploaded_filesWHEREuploaded_filesimageable_id= $ 1 ANDuploaded_filesimageable_type= $ 2 ORDER BYuploaded_files。idASC LIMIT 1 [0m [[imageable_id,6],[imageable_type,User]]
[1m [35m(0.0ms)[0m BEGIN
[1m [36m(0.0ms)[0m [1mROLLBACK [0m
在20ms内完成500内部服务器错误

NoMethodError - 未定义的方法`handle_dependency'为#< ActiveRecord ::协会:: HasAndBelongsToManyAssociation:0x8839440> ;:
activerecord(4.0.0)lib / active_record / associations / builder / association.rb:97:在`has_many_dependent_for_roles'
activesupport(4.0.0)lib / active_support / callbacks.rb:377:在`_run__282840259__destroy__callbacks'
activesupport(4.0.0)lib / active_support / callbacks.rb:80:在`run_callbacks'
activerecord(4.0.0)lib / active_record / callbacks.rb:289:在`destroy'
activerecord(4.0.0)lib / active_record / transactions.rb:265:在`block in destroy'
activerecord(4.0.0)lib / active_record / transactions.rb:326:在`block in with_transaction_returning_status'
activerecord(4.0.0)lib / active_record / connection_adapters / abstract / database_statements.rb:202:in `block in transaction'
activerecord(4.0.0)lib / active_record / connection_adapters / abstract / database_statements.rb:210:in`within_new_transaction'
activerecord(4.0.0)lib / active_record / connection_adapters / abstract /database_statements.rb:202:in`transaction'
activerecord(4.0.0)lib / active_record / transactions.rb:209:在`transaction'
activerecord(4.0.0)lib / active_record / transactions .rb:323:在`with_transaction_returning_status'
activerecord(4.0.0)lib / active_record / transactions.rb:265:在`destroy'
app / controllers / users_controller.rb:54:在`destroy
actionpack(4.0.0)lib / action_controller / metal / implicit_render.rb:4:在`send_action'
actionpack(4.0.0)lib / abstract_controller / base.rb:189:在'process_action'
actionpack(4.0.0)lib / action_controller / metal / rendering.rb:10:在'process_action'
actionpack(4.0.0)lib / abstract_controller / callbacks.rb:18:在`block in process_action'
activesupport(4.0.0)lib / active_support / callbacks.rb:463:在`_run__462102624__process_action__callbacks'
activesupport(4.0.0)lib / active_support / callbacks.rb:80:在`run_callbacks'
actionpack(4.0.0)lib / abstract_controller / callbacks.rb:17:在'process_action'
actionpack(4.0.0)lib / action_controller / metal / rescue.rb:29:在'process_action'
actionpack(4.0.0)lib / action_controller / metal / instrumentation.rb:31:在'block in process_action'
activesupport(4.0.0)lib / active_support / notifications.rb:159:in`在仪器'
activesupport(4.0.0)lib / active_support / notif中阻止ications / instrumenter.rb:20:在`instrument'
activesupport(4.0.0)lib / active_support / notifications.rb:159:在`instrument'
actionpack(4.0.0)lib / action_controller /金属/ instrumentation.rb:30:在'process_action'
actionpack(4.0.0)lib / action_controller / metal / params_wrapper.rb:245:在'process_action'
activerecord(4.0.0)lib / active_record / railties / controller_runtime.rb:18:在'process_action'
actionpack(4.0.0)lib / abstract_controller / base.rb:136:在'process'
actionpack(4.0.0)lib / abstract_controller / rendering.rb:44:in'process'
actionpack(4.0.0)lib / action_controller / metal.rb:195:在`dispatch'
actionpack(4.0.0)lib / action_controller /金属/ rack_delegation.rb:13:在`dispatch'
actionpack(4.0.0)lib / action_controller / metal.rb:231:在`block in action'
actionpack(4.0.0)lib / action_dispatch / routing / route_set.rb:80:在`dispatch'
actionpack(4.0.0)lib / action_dispatch / routing / route_set.rb:48:in `call'
actionpack(4.0.0)lib / action_dispatch / journey / router.rb:71:在`block in call'
actionpack(4.0.0)lib / action_dispatch / journey / router.rb :59:in`call'
actionpack(4.0.0)lib / action_dispatch / routing / route_set.rb:655:in`call'
omniauth(1.1.4)lib / omniauth / strategy.rb :184:在`call!'
omniauth(1.1.4)lib / omniauth / strategy.rb:164:在`call'
omniauth(1.1.4)lib / omniauth / strategy.rb: 184:在`call!'
omniauth(1.1.4)lib / omniauth / strategy.rb:164:在`call'
omniauth(1.1.4)lib / omniauth / strategy.rb:184 :$ call $'
omniauth(1.1.4)lib / omniauth / strategy.rb:164:在`call'
omniauth(1.1.4)lib / omniauth / strategy.rb:184:在`call''
omniauth(1.1.4)lib / omniauth / strategy.rb:164:在`call'
omniauth(1.1.4)lib / omniauth / strategy.rb:184:in 'call''
omniauth(1.1.4)lib / omniauth / strategy.rb:164:在`call'
omniauth(1.1.4)lib / omniauth / strategy.rb:184:in`打电话!'
omniauth(1。 1.4)lib / omniauth / strategy.rb:164:在`call'
omniauth(1.1.4)lib / omniauth / strategy.rb:184:在`call!'
omniauth(1.1.4 )lib / omniauth / strategy.rb:164:在`call'
omniauth(1.1.4)lib / omniauth / strategy.rb:184:在`call!'
omniauth(1.1.4) lib / omniauth / strategy.rb:164:在`call'
omniauth(1.1.4)lib / omniauth / strategy.rb:184:在`call!'
omniauth(1.1.4)lib /mnnuth/strategy.rb:164:in`call'
omniauth(1.1.4)lib / omniauth / builder.rb:49:在`call'
bullet(4.7.1)lib / bullet /rack.rb:10:in`call'
warden(1.2.3)lib / warden / manager.rb:35:在`block in call'
warden(1.2.3)lib / warden /manager.rb:34:in`call'
机架(1.5.2)lib / rack / etag.rb:23:在`call'
机架(1.5.2)lib / rack / conditionalget .rb:35:在`call'
机架(1.5.2)lib / rack / head.rb:11:在`call'
actionpack(4.0.0)lib / action_dispatch / middleware / params_parser .rb:27:在`call'
actionpack(4.0.0)lib / action_dispatch / middleware / fla sh.rb:241:在`call'
机架(1.5.2)lib / rack / session / abstract / id.rb:225:在`context'
机架(1.5.2)lib / rack / session / abstract / id.rb:220:in`call'
actionpack(4.0.0)lib / action_dispatch / middleware / cookies.rb:486:在`call'
activerecord(4.0。 0)lib / active_record / query_cache.rb:36:在`call'
activerecord(4.0.0)lib / active_record / connection_adapters / abstract / connection_pool.rb:626:在`call'
activerecord 4.0.0)lib / active_record / migration.rb:369:在`call'
actionpack(4.0.0)lib / action_dispatch / middleware / callbacks.rb:29:在`block in call'
activesupport(4.0.0)lib / active_support / callbacks.rb:373:在`_run__867238995__call__callbacks'
activesupport(4.0.0)lib / active_support / callbacks.rb:80:在`run_callbacks'
actionpack 4.0.0)lib / action_dispatch / middleware / callbacks.rb:27:在`call'
actionpack(4.0.0)lib / action_dispatch / middleware / reloader.rb:64:在`call'
actionpack(4.0.0)lib / action_disp atch / middleware / remote_ip.rb:76:在`call'
better_errors(1.0.1)lib / better_errors / middleware.rb:84:在`protected_app_call'
better_errors(1.0.1)lib / good_errors / middleware.rb:79:在`better_errors_call'
better_errors(1.0.1)lib / better_errors / middleware.rb:56:在`call'
actionpack(4.0.0)lib / action_dispatch /中间件/ debug_exceptions.rb:17:在`call'
actionpack(4.0.0)lib / action_dispatch / middleware / show_exceptions.rb:30:在`call'
railties(4.0.0)lib / rails / rack / logger.rb:38:在`call_app'
railties(4.0.0)lib / rails / rack / logger.rb:21:在`block in call'
activesupport(4.0。 0)lib / active_support / tagged_logging.rb:67:在`block in tagged'
activesupport(4.0.0)lib / active_support / tagged_logging.rb:25:在`tagged'
activesupport(4.0。 0)lib / active_support / tagged_logging.rb:67:在`tagged'
railties(4.0.0)lib / rails / rack / logger.rb:21:在`call'
quiet_assets(1.0。 2)lib / quiet_assets.rb:18:in `call_with_quiet_assets'
actionpack(4.0.0)lib / action_dispatch / middleware / request_id.rb:21:在`call'
机架(1.5.2)lib / rack / methodoverride.rb:21:in `call'
rack(1.5.2)lib / rack / runtime.rb:17:in`call'
activesupport(4.0.0)lib / active_support / cache / strategy / local_cache.rb:83 :在`call'
机架(1.5.2)lib / rack / lock.rb:17:在`call'
actionpack(4.0.0)lib / action_dispatch / middleware / static.rb:64 :在`call'
railties(4.0.0)lib / rails / engine.rb:511:在`call'
railties(4.0.0)lib / rails / application.rb:97:in `call'
rack(1.5.2)lib / rack / content_length.rb:14:在`call'
thin(1.6.1)lib / thin / connection.rb:82:在`block在pre_process'
thin(1.6.1)lib / thin / connection.rb:80:在`pre_process'
thin(1.6.1)lib / thin / connection.rb:55:在'进程'
thin(1.6.1)lib / thin / connection.rb:41:在`receive_data'
eventmachine-1.0.3-x86(mingw32)lib / eventmachine.rb:187:在`run '
thin(1.6 .1)lib / thin / backends / base.rb:73:在`start'
thin(1.6.1)lib / thin / server.rb:162:在`start'
机架.2)lib / rack / handler / thin.rb:16:在`run'
机架(1.5.2)lib / rack / server.rb:264:在`start'
railties(4.0 .0)lib / rails / commands / server.rb:84:在`start'
railties(4.0.0)lib / rails / commands.rb:78:在`block in< top(required)> ;
railties(4.0.0)lib / rails / commands.rb:73:in`< top(required)>'
bin / rails:4:in`< main>


解决方案

rolify resourcify 用户作用。确保您有最新版本的rolify(bundle update rolify)并重新启动服务器和控制台。



handle_dependency 错误表示:roles 关联正被覆盖。



在查看rolify.rb后,来源,我发现:



1。问题: rolify resourcify 都创建了一个关联:roles



以下GitHub问题寻求尝试 rolify resourcify 用户



未定义的方法查找或创建



要解决此问题,需要进行以下更改: / p>

  class User< ActiveRecord :: Base 
resourcify:resources#必须在rolify之前放置

我已经成功解决 handle_dependency 错误,但我关心下一个问题。



2。问题: rolify resourcify 都设置了一个适配器 / strong>



Rolify resourcify 都设置相同的实例变量适配器这是角色或资源特定的。有人评论说,这是一个问题 here 。由于某种原因,我还没有遇到这个问题,但我希望可以。



我的解决方案是替换适配器 role_adapter resource_adapter 并更新适配器在整个剩余的rolify代码中使用特定的必需的适配器这个希望将允许 rolify resourcify 一个模型的能力。


$ b $我还没有测试过,但是我有时间会尝试。


Is there a way to destroy user from a users controller?

I do have a users resource defined in routes.rb and also below method for Users Controller

  def destroy
    @user.destroy
    head :no_content
  end

This however creates below error:

undefined method `handle_dependency' for #<ActiveRecord::Associations::HasAndBelongsToManyAssociation:0x8839440>

I'm trying to locate what this error stands for and the appropriate fix for it. What could be the cause?

User model

class User < ActiveRecord::Base
  resourcify

  after_create :assign_default_role
  rolify :before_add => :before_add_method
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :confirmable, :omniauthable

  has_many :venues, dependent: :destroy
  has_many :from_user_chats, :foreign_key => 'from_user_id', :class_name => 'Chat'
  has_many :to_user_chats, :foreign_key => 'to_user_id', :class_name => 'Chat'
  has_one :uploaded_file, as: :imageable, dependent: :destroy
  accepts_nested_attributes_for :uploaded_file, :reject_if => proc { |attributes| attributes['assets'].blank? }

  def name
    "#{first_name} #{last_name}"
  end

  def before_add_method(role)
    # do something
  end

  def assign_default_role
    add_role :visitor
  end

  def self.from_omniauth(auth)
    where(auth.slice(:provider, :uid)).first_or_create do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.username = auth.info.nickname
    end
  end

  def self.new_with_session(params, session)
    if session["devise.user_attributes"]
      new(session["devise.user_attributes"], without_protection: true) do |user|
        user.attributes = params
        user.valid?
      end
    else
      super
    end
  end

  def password_required?
    super && provider.blank?
  end

  def update_with_password(params, *options)
    if encrypted_password.blank?
      update_attributes(params, *options)
    else
      super
    end
  end

end

Stack trace:

Started DELETE "/users/6" for 127.0.0.1 at 2014-01-22 20:33:08 +1100
Processing by UsersController#destroy as HTML
  Parameters: {"authenticity_token"=>"T5pbLtoI0MAiaFW0x24LXdlospa4b8ogVtdLbhqEYyc=", "id"=>"6"}
  [1m[36mUser Load (1.0ms)[0m  [1mSELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1[0m
  [1m[35mUploadedFile Load (0.0ms)[0m  SELECT "uploaded_files".* FROM "uploaded_files" WHERE "uploaded_files"."imageable_id" = $1 AND "uploaded_files"."imageable_type" = $2 ORDER BY "uploaded_files"."id" ASC LIMIT 1  [["imageable_id", 1], ["imageable_type", "User"]]
  [1m[36mUser Load (0.0ms)[0m  [1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1[0m  [["id", "6"]]
  [1m[35m (0.0ms)[0m  SELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 1]]
  [1m[36m (0.0ms)[0m  [1mSELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND "roles"."name" = 'admin'[0m  [["user_id", 1]]
  [1m[35mRole Load (0.0ms)[0m  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND "roles"."name" = 'admin'  [["user_id", 1]]
  [1m[36m (1.0ms)[0m  [1mSELECT "products"."id" FROM "products" INNER JOIN "roles" ON "roles".resource_type = 'Product' AND
 ("roles".resource_id IS NULL OR "roles".resource_id = "products".id) WHERE ("roles".name IN ('admin') AND "roles".resource_type = 'Product') AND ("roles".id IN (3) AND ((resource_id = "products".id) OR (resource_id IS NULL)))[0m
  [1m[35mCACHE (0.0ms)[0m  SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", "6"]]
  [1m[36mUploadedFile Load (0.0ms)[0m  [1mSELECT "uploaded_files".* FROM "uploaded_files" WHERE "uploaded_files"."imageable_id" = $1 AND "uploaded_files"."imageable_type" = $2 ORDER BY "uploaded_files"."id" ASC LIMIT 1[0m  [["imageable_id", 6], ["imageable_type", "User"]]
  [1m[35m (0.0ms)[0m  BEGIN
  [1m[36m (0.0ms)[0m  [1mROLLBACK[0m
Completed 500 Internal Server Error in 20ms

NoMethodError - undefined method `handle_dependency' for #<ActiveRecord::Associations::HasAndBelongsToManyAssociation:0x8839440>:
  activerecord (4.0.0) lib/active_record/associations/builder/association.rb:97:in `has_many_dependent_for_roles'
  activesupport (4.0.0) lib/active_support/callbacks.rb:377:in `_run__282840259__destroy__callbacks'
  activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
  activerecord (4.0.0) lib/active_record/callbacks.rb:289:in `destroy'
  activerecord (4.0.0) lib/active_record/transactions.rb:265:in `block in destroy'
  activerecord (4.0.0) lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
  activerecord (4.0.0) lib/active_record/transactions.rb:209:in `transaction'
  activerecord (4.0.0) lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
  activerecord (4.0.0) lib/active_record/transactions.rb:265:in `destroy'
  app/controllers/users_controller.rb:54:in `destroy'
  actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
  actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (4.0.0) lib/active_support/callbacks.rb:463:in `_run__462102624__process_action__callbacks'
  activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
  activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
  activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
  actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
  activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
  actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
  actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
  actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
  actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
  actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
  omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
  omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.1.4) lib/omniauth/builder.rb:49:in `call'
  bullet (4.7.1) lib/bullet/rack.rb:10:in `call'
  warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.3) lib/warden/manager.rb:34:in `call'
  rack (1.5.2) lib/rack/etag.rb:23:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
  activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
  activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__867238995__call__callbacks'
  activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
  actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
  better_errors (1.0.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (1.0.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (1.0.1) lib/better_errors/middleware.rb:56:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
  quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
  actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0) lib/rails/engine.rb:511:in `call'
  railties (4.0.0) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  thin (1.6.1) lib/thin/connection.rb:82:in `block in pre_process'
  thin (1.6.1) lib/thin/connection.rb:80:in `pre_process'
  thin (1.6.1) lib/thin/connection.rb:55:in `process'
  thin (1.6.1) lib/thin/connection.rb:41:in `receive_data'
  eventmachine-1.0.3-x86 (mingw32) lib/eventmachine.rb:187:in `run'
  thin (1.6.1) lib/thin/backends/base.rb:73:in `start'
  thin (1.6.1) lib/thin/server.rb:162:in `start'
  rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
  rack (1.5.2) lib/rack/server.rb:264:in `start'
  railties (4.0.0) lib/rails/commands/server.rb:84:in `start'
  railties (4.0.0) lib/rails/commands.rb:78:in `block in <top (required)>'
  railties (4.0.0) lib/rails/commands.rb:73:in `<top (required)>'
  bin/rails:4:in `<main>'

解决方案

I've investigated this as I'm trying to rolify and resourcify a model other than User or Role. Make sure you have the latest version of rolify ("bundle update rolify") and restart your server and console.

The handle_dependency error indicates that the :roles association is being overwritten.

After looking at rolify.rb in the source, I found:

1. Problem: rolify and resourcify are both creating an association :roles

The following GitHub issue addresses attempting to rolify and resourcify User.

Undefined method find or create by

To resolve this issue, the following change is needed:

class User < ActiveRecord::Base
  resourcify :resources # Must be placed before rolify

I've had success resolving the handle_dependency error, but I'm concerned with the next problem.

2. Problem: rolify and resourcify are both setting an adapter

Rolify and resourcify both set the same instance variable adapter that is role or resource specific. Someone has commented that this is a problem here. For some reason I haven't encountered this yet, but I expect to.

My solution would be to replace adapter in 'rolify.rb' with two new instance variables role_adapter and resource_adapter and update adapter throughout the rest of the rolify code with the specific required adapter. This hopefully will allow the ability to rolify and resourcify a model.

I haven't tested this yet but I'll try when I have time.

这篇关于如何从用户控制器中删除设计用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆