本文介绍了引发ArgumentError在设计:: RegistrationsController#新错误的参数数目(2 0..1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Im在装置和后omniauth以下瑞恩·贝茨RailsCast(情节235色器件和-omniauth-修订)。我不断收到错误的标题时,我试图与Twitter登录。

 高清self.new_with_session(参数,可以会话)
如果会话[devise.user_attributes]
新(会话[devise.user_attributes],without_protection:真)做|用户|
user.attributes =参数
user.valid?
结束

完整跟踪:

<$p$p><$c$c>C:/Ruby200-x64/lib/ruby/gems/2.0.0/bundler/gems/mongoid-fe7f43430580/lib/mongoid/document.rb:106:in `初始化
设计(3.0.0.rc)的lib /设计/模型/ confirmable.rb:46:在`初始化
应用程序/模型/用户/ user.rb:58:在`新'
应用程序/模型/用户/ user.rb:58:在`new_with_session
设计(3.0.0.rc)应用程序/控制器/设计/ registrations_controller.rb:86:在`build_resource
设计(3.0.0.rc)应用程序/控制器/设计/ registrations_controller.rb:7:'新'
ActionPack的(4.0.0.rc1)的lib / action_controller /金属/ implicit_render.rb:4:`send_action
ActionPack的(4.0.0.rc1)的lib / abstract_controller / base.rb:189:在`process_action
ActionPack的(4.0.0.rc1)的lib / action_controller /金属/ rendering.rb:10:`process_action
ActionPack的(4.0.0.rc1)的lib / abstract_controller / callbacks.rb:18:在`在process_action块
的ActiveSupport(4.0.0.rc1)的lib / active_support / callbacks.rb:442:在`_run__1463920666__process_action__callbacks
的ActiveSupport(4.0.0.rc1)的lib / active_support / callbacks.rb:80:在`run_callbacks
ActionPack的(4.0.0.rc1)的lib / abstract_controller / callbacks.rb:17:在`process_action
ActionPack的(4.0.0.rc1)的lib / action_controller /金属/ rescue.rb:29:在`process_action
ActionPack的(4.0.0.rc1)的lib / action_controller /金属/ instrumentation.rb:31:在`在process_action块
的ActiveSupport(4.0.0.rc1)的lib / active_support / notifications.rb:159:在`仪表块
的ActiveSupport(4.0.0.rc1)的lib / active_support /通知/ instrumenter.rb:20:'仪'
的ActiveSupport(4.0.0.rc1)的lib / active_support / notifications.rb:159:在`仪器
ActionPack的(4.0.0.rc1)的lib / action_controller /金属/ instrumentation.rb:30:在`process_action
ActionPack的(4.0.0.rc1)的lib / action_controller /金属/ params_wrapper.rb:245:在`process_action
ActionPack的(4.0.0.rc1)的lib / abstract_controller / base.rb:136:在'过程'
ActionPack的(4.0.0.rc1)的lib / abstract_controller / rendering.rb:44:在'过程'
ActionPack的(4.0.0.rc1)的lib / action_controller / metal.rb:195:在`派遣
ActionPack的(4.0.0.rc1)的lib / action_controller /金属/ rack_delegation.rb:13:'派遣'
ActionPack的(4.0.0.rc1)的lib / action_controller / metal.rb:231:在`在行动块
ActionPack的(4.0.0.rc1)的lib / action_dispatch /路由/ route_set.rb:80:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /路由/ route_set.rb:80:在'调度'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /路由/ route_set.rb:48:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /路由/ mapper.rb:44:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /旅程/ router.rb:71:在'呼叫块
ActionPack的(4.0.0.rc1)的lib / action_dispatch /旅程/ router.rb:59:在每个`
ActionPack的(4.0.0.rc1)的lib / action_dispatch /旅程/ router.rb:59:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /路由/ route_set.rb:654​​:在`呼叫'
omn​​iauth(1.1.4)的lib / omniauth / strategy.rb:184:在'称之为'
omn​​iauth(1.1.4)的lib / omniauth / strategy.rb:164:在`呼叫'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/bundler/gems/mongoid-fe7f43430580/lib/rack/mongoid/middleware/identity_map.rb:34:in呼叫'块'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/bundler/gems/mongoid-fe7f43430580/lib/mongoid/unit_of_work.rb:39:in `unit_of_work
C:/Ruby200-x64/lib/ruby/gems/2.0.0/bundler/gems/mongoid-fe7f43430580/lib/rack/mongoid/middleware/identity_map.rb:34:in `叫'
舍监(1.2.1)的lib /监狱长/ manager.rb:35:在'呼叫块
舍监(1.2.1)的lib /监狱长/ manager.rb:34:在'抓'
舍监(1.2.1)的lib /监狱长/ manager.rb:34:在`呼叫'
机架(1.5.2)的lib /架/ etag.rb:23:在'叫'
机架(1.5.2)的lib /架/ conditionalget.rb:25:在'叫'
机架(1.5.2)的lib /架/ head.rb:11:'叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ params_parser.rb:27:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ flash.rb:241:在`呼叫'
机架(1.5.2)的lib /架/会话/抽象/ id.rb:225:在'背景'
机架(1.5.2)的lib /架/会话/抽象/ id.rb:220:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ cookies.rb:486:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ callbacks.rb:29:在'呼叫块
的ActiveSupport(4.0.0.rc1)的lib / active_support / callbacks.rb:392:在`_run__1122738349__call__callbacks
的ActiveSupport(4.0.0.rc1)的lib / active_support / callbacks.rb:80:在`run_callbacks
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ callbacks.rb:27:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ reloader.rb:64:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ remote_ip.rb:76:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ debug_exceptions.rb:17:在`呼叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ show_exceptions.rb:30:在`呼叫'
railties(4.0.0.rc1)的lib /导轨/架/ logger.rb:38:在`call_app
railties(4.0.0.rc1)的lib /导轨/架/ logger.rb:21:在'呼叫块
的ActiveSupport(4.0.0.rc1)的lib / active_support / tagged_logging.rb:67:在`块标记
的ActiveSupport(4.0.0.rc1)的lib / active_support / tagged_logging.rb:25:在`标签
的ActiveSupport(4.0.0.rc1)的lib / active_support / tagged_logging.rb:67:在`标签
railties(4.0.0.rc1)的lib /导轨/架/ logger.rb:21:在'叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ request_id.rb:21:在`呼叫'
机架(1.5.2)的lib /架/ methodoverride.rb:21:在'叫'
机架(1.5.2)的lib /架/ runtime.rb:17:在'叫'
的ActiveSupport(4.0.0.rc1)的lib / active_support /缓存/策略/ local_cache.rb:83:在`呼叫'
机架(1.5.2)的lib /架/ lock.rb:17:在'叫'
ActionPack的(4.0.0.rc1)的lib / action_dispatch /中间件/ static.rb:64:在`呼叫'
railties(4.0.0.rc1)的lib /导轨/ engine.rb:511:在`呼叫'
railties(4.0.0.rc1)的lib /导轨/ application.rb中:96:在`呼叫'
机架(1.5.2)的lib /架/ lock.rb:17:在'叫'
机架(1.5.2)的lib /架/ content_length.rb:14:'叫'
机架(1.5.2)的lib /架/处理器/ webrick.rb:60:在'服务'
C:/Ruby200-x64/lib/ruby/2.0.0/webrick/httpserver.rb:138:'服务'
C:/Ruby200-x64/lib/ruby/2.0.0/webrick/httpserver.rb:94:在`跑
C:/Ruby200-x64/lib/ruby/2.0.0/webrick/server.rb:295:在`在start_thread块

还是很新的回报率和所有的所以任何帮助将是最欢迎的。


解决方案

在您的应用程序跟踪我可以看到你正在使用Rails 4现在消除质量分配为模型,并已与strong_parameters宝石为默认取而代之。

因此​​,在创建新记录时,你可以删除'without_protection'选项,因为它不再执行。

code的新行应为:

 新会话[devise.user_attributes]做|用户|

Im following Ryan bates RailsCast on devise and omniauth (episode 235-devise-and-omniauth-revised). I keep getting the error in the title when i try to log in with twitter.

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

Full trace:

C:/Ruby200-x64/lib/ruby/gems/2.0.0/bundler/gems/mongoid-fe7f43430580/lib/mongoid/document.rb:106:in `initialize'
devise (3.0.0.rc) lib/devise/models/confirmable.rb:46:in `initialize'
app/models/user/user.rb:58:in `new'
app/models/user/user.rb:58:in `new_with_session'
devise (3.0.0.rc) app/controllers/devise/registrations_controller.rb:86:in `build_resource'
devise (3.0.0.rc) app/controllers/devise/registrations_controller.rb:7:in `new'
actionpack (4.0.0.rc1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0.rc1) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0.rc1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:442:in `_run__1463920666__process_action__callbacks'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0.rc1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0.rc1) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0.rc1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0.rc1) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0.rc1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0.rc1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
actionpack (4.0.0.rc1) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0.rc1) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0.rc1) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0.rc1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0.rc1) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/mapper.rb:44:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0.rc1) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0.rc1) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/routing/route_set.rb:654:in `call'
omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/bundler/gems/mongoid-fe7f43430580/lib/rack/mongoid/middleware/identity_map.rb:34:in `block in call'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/bundler/gems/mongoid-fe7f43430580/lib/mongoid/unit_of_work.rb:39:in `unit_of_work'
C:/Ruby200-x64/lib/ruby/gems/2.0.0/bundler/gems/mongoid-fe7f43430580/lib/rack/mongoid/middleware/identity_map.rb:34:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) 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:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0.rc1) 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.rc1) lib/action_dispatch/middleware/cookies.rb:486:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:392:in `_run__1122738349__call__callbacks'
activesupport (4.0.0.rc1) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0.rc1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0.rc1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0.rc1) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0.rc1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0.rc1) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0.rc1) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0.rc1) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0.rc1) 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.rc1) 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.rc1) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0.rc1) lib/rails/engine.rb:511:in `call'
railties (4.0.0.rc1) lib/rails/application.rb:96:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/Ruby200-x64/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
C:/Ruby200-x64/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
C:/Ruby200-x64/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

Still very new to RoR and all that so any help will be most welcome.

解决方案

In your application trace I can see that you are using Rails 4 which now removes mass assignment for models and has replaced it with the strong_parameters gem as default.

Therefore, when creating new records you can remove the 'without_protection' option as it is no longer implemented.

The new line of code should read:

new session["devise.user_attributes"] do |user|

这篇关于引发ArgumentError在设计:: RegistrationsController#新错误的参数数目(2 0..1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:07