添加新的设计用户类型会在Devise :: SessionsController #new中创建ArgumentError

时间:2021-06-14 15:28:19

I'm using rails 4.2 and devise 3.4.1

我正在使用rails 4.2并设计3.4.1

I've got a devise user type called entrant which is working fine. I've customised it slightly with a custom controller called registration.

我有一个名为entrant的设计用户类型,工作正常。我用一个名为registration的自定义控制器稍微定制了它。

I've added a new user type called admin like this

我添加了一个名为admin的新用户类型

rails generate devise Admin
rake db:migrate 

Then I've generated the views with

然后我用它生成了视图

rails generate devise:views admins 

When I visit the sign in URL for admins (/admins/sign_up) I get the following error

当我访问admins的登录URL(/ admins / sign_up)时,出现以下错误

ArgumentError in Devise::RegistrationsController#new
wrong number of arguments (2 for 1)

Extracted source (around line #466):
    args = key[-2, 2]

I've restarted my rails server, but I've no idea what else to do. Does anyone know why I'm getting this error. I also get the same error for other routes like /admins/sign_in

我重启了我的rails服务器,但我不知道还能做什么。有谁知道为什么我收到这个错误。对于/ admins / sign_in等其他路由,我也会遇到同样的错误

I've done this successfully before with other versions of Rails and Devise and its worked fine.

我之前使用其他版本的Rails和Devise成功完成了这项工作,并且工作正常。

Here is the application trace

这是应用程序跟踪

devise (3.4.1) lib/devise.rb:466:in `[]'
devise (3.4.1) lib/devise.rb:466:in `block (2 levels) in configure_warden!'
warden (1.2.3) lib/warden/session_serializer.rb:34:in `fetch'
warden (1.2.3) lib/warden/proxy.rb:212:in `user'
warden (1.2.3) lib/warden/proxy.rb:318:in `_perform_authentication'
warden (1.2.3) lib/warden/proxy.rb:104:in `authenticate'
warden (1.2.3) lib/warden/proxy.rb:114:in `authenticate?'
devise (3.4.1) app/controllers/devise_controller.rb:103:in `require_no_authentication'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:432:in `block in make_lambda'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:145:in `call'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:145:in `block in halting_and_conditional'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:504:in `call'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:504:in `block in call'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:504:in `each'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:504:in `call'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1.rc3) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.1.rc3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.1.rc3) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.1.rc3) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.1.rc3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.1.rc3) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.1.rc3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.1.rc3) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.1.rc3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.1.rc3) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.1.rc3) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.1.rc3) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.1.rc3) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.1.rc3) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.1.rc3) lib/action_dispatch/routing/route_set.rb:74:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.1.rc3) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.1.rc3) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.1.rc3) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.1.rc3) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.1.rc3) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.1.rc3) lib/action_dispatch/routing/route_set.rb:819: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 `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.1.rc3) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.1.rc3) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
activerecord (4.2.1.rc3) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
activesupport (4.2.1.rc3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.1.1) lib/web_console/middleware.rb:37:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.1.rc3) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.1.rc3) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.1.rc3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.1.rc3) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.1.rc3) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.1.rc3) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.1.rc3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.1.rc3) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.1.rc3) lib/rails/engine.rb:518:in `call'
railties (4.2.1.rc3) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
/Users/neil/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/neil/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/neil/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

Here is my routes.rb file

这是我的routes.rb文件

Rails.application.routes.draw do

  resources :entries
  devise_for :entrants, :controllers => { registrations: 'registrations' }
  resources :charges
  devise_for :admins
  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"
  root 'home#index'
end

Here is the registrations_controller.rb

这是registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController

  private

  def sign_up_params
    params.require(:entrant).permit(:first_name, :last_name, :email, :password, :password_confirmation)
  end

  def account_update_params
    params.require(:entrant).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password, :title, :address, :postcode, :main_phone_number, :secondary_phone_number, :website, :dob, :place_of_birth, :place_of_education, :degree_attained, :how_did_you_hear_about_newlight, :terms_of_service)
   end


  def after_update_path_for(resource)
    #edit_entrant_registration_path(resource)
    entries_path
  end

  def after_sign_up_path_for(resource)
    edit_entrant_registration_path(resource)
  end

end

2 个解决方案

#1


I'm not an expert so I can't give you the exact reason why you and me both were having this problem but --

我不是专家,所以我不能告诉你为什么你和我都有这个问题的确切原因但是 -

I was getting this line in the application trace, just like you:

我在应用程序跟踪中得到了这一行,就像你一样:

warden (1.2.3) lib/warden/session_serializer.rb:34:in `fetch'

After some digging, I figured out the problem was with the current session, so I opened up a new 'incognito' browser window and the error was gone.

经过一番挖掘,我发现问题出在当前会话中,所以我打开了一个新的“隐身”浏览器窗口,错误消失了。

You should be able to solve this problem by erasing your cookies and history from your browser.

您应该可以通过从浏览器中删除Cookie和历史记录来解决此问题。

#2


I have no idea why this worked, but it must have been a conflict with versions or something.

我不知道为什么会这样,但它肯定是与版本或其他东西的冲突。

I reinstalled RVM, then installed ruby 2.2.2 and Rubygems 2.4.6 then reinstalled rails and it works now with devise 3.4.1

我重新安装了RVM,然后安装了ruby 2.2.2和Rubygems 2.4.6,然后重新安装了rails,它现在可以使用设计3.4.1

#1


I'm not an expert so I can't give you the exact reason why you and me both were having this problem but --

我不是专家,所以我不能告诉你为什么你和我都有这个问题的确切原因但是 -

I was getting this line in the application trace, just like you:

我在应用程序跟踪中得到了这一行,就像你一样:

warden (1.2.3) lib/warden/session_serializer.rb:34:in `fetch'

After some digging, I figured out the problem was with the current session, so I opened up a new 'incognito' browser window and the error was gone.

经过一番挖掘,我发现问题出在当前会话中,所以我打开了一个新的“隐身”浏览器窗口,错误消失了。

You should be able to solve this problem by erasing your cookies and history from your browser.

您应该可以通过从浏览器中删除Cookie和历史记录来解决此问题。

#2


I have no idea why this worked, but it must have been a conflict with versions or something.

我不知道为什么会这样,但它肯定是与版本或其他东西的冲突。

I reinstalled RVM, then installed ruby 2.2.2 and Rubygems 2.4.6 then reinstalled rails and it works now with devise 3.4.1

我重新安装了RVM,然后安装了ruby 2.2.2和Rubygems 2.4.6,然后重新安装了rails,它现在可以使用设计3.4.1