Rails强参数ActiveModel :: ForbiddenAttributesError

时间:2015-09-09 18:03:12

标签: ruby-on-rails activerecord strong-parameters

嗨,我知道Rails 4正在使用强参数,我需要在控制器中允许它们,这是我的工作,但我仍然会收到此错误。

我的请求看起来像是

{"utf8"=>"✓",
"authenticity_token"=>"cAJLJGiywr4TeAEpidQ1/XstiSNO+819W4QBhgMGNczVret+H/XDDVk3l1UpoaK8tHVK6qf+KK8VjBdM51zocA==",
"estate"=>{"building_id"=>"1",
"planet_id"=>"1",
"number"=>"2"},
"commit"=>"Build",
"locale"=>"en"}

在我的控制器中我试过

def estate_params
    params.require(:estate).permit(:building_id, :planet_id, :number)
end


@estate = Estate.new(estate_params)

Estate.new(params[:estate].permit(:building_id, :planet_id, :number))

任何人都可以向我解释为什么我会收到此错误?

由于

完整追踪

.bundle/gems/activemodel-4.2.0/lib/active_model/forbidden_attributes_protection.rb:21:in     `sanitize_for_mass_assignment'
.bundle/gems/activerecord-4.2.0/lib/active_record/attribute_assignment.rb:33:in `assign_attributes'
.bundle/gems/activerecord-4.2.0/lib/active_record/core.rb:557:in `init_attributes'
.bundle/gems/activerecord-4.2.0/lib/active_record/core.rb:280:in `initialize'
.bundle/gems/activerecord-4.2.0/lib/active_record/inheritance.rb:61:in `new'
.bundle/gems/activerecord-4.2.0/lib/active_record/inheritance.rb:61:in `new'
.bundle/gems/cancan-1.6.10/lib/cancan/controller_resource.rb:85:in `build_resource'
.bundle/gems/cancan-1.6.10/lib/cancan/controller_resource.rb:66:in `load_resource_instance'
.bundle/gems/cancan-1.6.10/lib/cancan/controller_resource.rb:32:in `load_resource'
.bundle/gems/cancan-1.6.10/lib/cancan/controller_resource.rb:25:in `load_and_authorize_resource'
.bundle/gems/cancan-1.6.10/lib/cancan/controller_resource.rb:10:in `block in add_before_filter'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:443:in `instance_exec'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:443:in `block in make_lambda'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:163:in `call'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:163:in `block in halting'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `call'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `call'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `block in halting'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `call'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `block in halting'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting'
.bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'

.bundle / gems / activesupport-4.2.0 / lib / active_support / callbacks.rb:169:in block in halting' .bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in call' .bundle / gems / activesupport-4.2.0 / lib / active_support / callbacks.rb:92:in _run_callbacks' .bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in _ run_process_action_callbacks' .bundle / gems / activesupport-4.2.0 / lib / active_support / callbacks.rb:81:in run_callbacks' .bundle/gems/actionpack-4.2.0/lib/abstract_controller/callbacks.rb:19:in process_action' .bundle / gems / actionpack-4.2.0 / lib / action_controller / metal / rescue.rb:29:在process_action中的process_action' .bundle/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:31:in块中 .bundle / gems / activesupport-4.2.0 / lib / active_support / notifications.rb:164:in block in instrument' .bundle/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in instrument' .bundle / gems / activesupport-4.2.0 / lib / active_support / notifications.rb:164:in instrument' .bundle/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:30:in process_action' .bundle / gems / actionpack-4.2.0 / lib / action_controller / metal / params_wrapper.rb:250:in process_action' .bundle/gems/activerecord-4.2.0/lib/active_record/railties/controller_runtime.rb:18:in process_action' .bundle / gems / actionpack-4.2.0 / lib / abstract_controller / base.rb:137:在process' .bundle/gems/actionview-4.2.0/lib/action_view/rendering.rb:30:in进程中 .bundle / gems / actionpack-4.2.0 / lib / action_controller / metal.rb:195:in dispatch' .bundle/gems/actionpack-4.2.0/lib/action_controller/metal/rack_delegation.rb:13:in dispatch' .bundle / gems / actionpack-4.2.0 / lib / action_controller / metal.rb:236:in block in action' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:73:in call' .bundle / gems / actionpack-4.2.0 / lib / action_dispatch / routing / route_set.rb:73:in dispatch' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:42:in serve' .bundle / gems / actionpack-4.2.0 / lib / action_dispatch / journey / router.rb:43:in block in serve' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/journey/router.rb:30:in each' .bundle / gems / actionpack-4.2.0 / lib / action_dispatch / journey / router.rb:30:in serve' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:802:in call' .bundle / gems / rack-pjax-0.8.0 / lib / rack / pjax.rb:12:in call' .bundle/gems/warden-1.2.3/lib/warden/manager.rb:35:in块中的呼叫' .bundle / gems / warden-1.2.3 / lib / warden / manager.rb:34:in catch' .bundle/gems/warden-1.2.3/lib/warden/manager.rb:34:in call' .bundle / gems / rack-1.6.4 / lib / rack / etag.rb:24:in call' .bundle/gems/rack-1.6.4/lib/rack/conditionalget.rb:38:in call' .bundle / gems / rack-1.6.4 / lib / rack / head.rb:13:in call' .bundle/gems/remotipart-1.2.1/lib/remotipart/middleware.rb:27:in call' .bundle / gems / actionpack-4.2.0 / lib / action_dispatch / middleware / params_parser.rb:27:in call' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/middleware/flash.rb:260:in call' .bundle / gems / rack-1.6.4 / lib / rack / session / abstract / id.rb:225:in context' .bundle/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in call' .bundle / gems / actionpack-4.2.0 / lib / action_dispatch / middleware / cookies.rb:560:in call' .bundle/gems/activerecord-4.2.0/lib/active_record/query_cache.rb:36:in call' .bundle / gems / activerecord-4.2.0 / lib / active_record / connection_adapters / abstract / connection_pool.rb:647:in call' .bundle/gems/activerecord-4.2.0/lib/active_record/migration.rb:378:in call' .bundle / gems / actionpack-4.2.0 / lib / action_dispatch / middleware / callbacks.rb:29:in block in call' .bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:88:in call' .bundle / gems / activesupport-4.2.0 / lib / active_support / callbacks.rb:88:in _run_callbacks' .bundle/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in _ run_call_callbacks' .bundle / gems / activesupport-4.2.0 / lib / active_support / callbacks.rb:81:in run_callbacks' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/middleware/callbacks.rb:27:in call' .bundle / gems / actionpack-4.2.0 / lib / action_dispatch / middleware / reloader.rb:73:in call' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/middleware/remote_ip.rb:78:in call' .bundle / gems / better_errors-2.1.1 / lib / better_errors / middleware.rb:59:in call' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/middleware/debug_exceptions.rb:17:in call' .bundle / gems / web-console-2.2.1 / lib / web_console / middleware.rb:31:in call' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/middleware/show_exceptions.rb:30:in call' .bundle / gems / railties-4.2.0 / lib / rails / rack / logger.rb:38:in call_app' .bundle/gems/railties-4.2.0/lib/rails/rack/logger.rb:20:in阻止通话' .bundle / gems / activesupport-4.2.0 / lib / active_support / tagged_logging.rb:68:in block in tagged' .bundle/gems/activesupport-4.2.0/lib/active_support/tagged_logging.rb:26:in tagged' .bundle / gems / activesupport-4.2.0 / lib / active_support / tagged_logging.rb:68:in tagged' .bundle/gems/railties-4.2.0/lib/rails/rack/logger.rb:20:in call' .bundle / gems / quiet_assets-1.1.0 / lib / quiet_assets.rb:27:in call_with_quiet_assets' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/middleware/request_id.rb:21:in call' .bundle / gems / rack-1.6.4 / lib / rack / methodoverride.rb:22:in call' .bundle/gems/rack-1.6.4/lib/rack/runtime.rb:18:in call' .bundle / gems / activesupport-4.2.0 / lib / active_support / cache / strategy / local_cache_middleware.rb:28:in call' .bundle/gems/actionpack-4.2.0/lib/action_dispatch/middleware/static.rb:113:in call' .bundle / gems / rack-1.6.4 / lib / rack / sendfile.rb:113:在call' .bundle/gems/railties-4.2.0/lib/rails/engine.rb:518:in调用' .bundle / gems / railties-4.2.0 / lib / rails / application.rb:164:in call' .bundle/gems/rack-1.6.4/lib/rack/content_length.rb:15:in call' .bundle / gems / thin-1.6.3 / lib / thin / connection.rb:86:in block in pre_process' .bundle/gems/thin-1.6.3/lib/thin/connection.rb:84:in catch' .bundle / gems / thin-1.6.3 / lib / thin / connection.rb:84:in pre_process' .bundle/gems/thin-1.6.3/lib/thin/connection.rb:53:in process' .bundle / gems / faye-websocket-0.10.0 / lib / faye / adapters / thin.rb:40:in process' .bundle/gems/thin-1.6.3/lib/thin/connection.rb:39:in receive_data' .bundle / gems / faye-websocket-0.10.0 / lib / faye / adapters / thin.rb:44:in receive_data' .bundle/gems/eventmachine-1.0.8/lib/eventmachine.rb:193:in run_machine' .bundle / gems / eventmachine-1.0.8 / lib / eventmachine.rb:193:in run' .bundle/gems/thin-1.6.3/lib/thin/backends/base.rb:73:in start' .bundle / gems / thin-1.6.3 / lib / thin / server.rb:162:in start' .bundle/gems/rack-1.6.4/lib/rack/handler/thin.rb:19:in run' .bundle / gems / rack-1.6.4 / lib / rack / server.rb:286:in start' .bundle/gems/railties-4.2.0/lib/rails/commands/server.rb:80:in start' .bundle / gems / railties-4.2.0 / lib / rails / commands / commands_tasks.rb:80:in block in server' .bundle/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in tap' .bundle / gems / railties-4.2.0 / lib / rails / commands / commands_tasks.rb:75:in server' .bundle/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in run_command!' .bundle / gems / railties-4.2.0 / lib / rails / commands.rb:17:in <top (required)>' bin/rails:8:in require' bin / rails:8:in <top (required)>' .bundle/gems/spring-1.3.6/lib/spring/client/rails.rb:28:in load' .bundle / gems / spring-1.3.6 / lib / spring / client / rails.rb:28:in call' .bundle/gems/spring-1.3.6/lib/spring/client/command.rb:7:in call' .bundle / gems / spring-1.3.6 / lib / spring / client.rb:26:in run' .bundle/gems/spring-1.3.6/bin/spring:48:in' .bundle / gems / spring-1.3.6 / lib / spring / binstub.rb:11:in load' .bundle/gems/spring-1.3.6/lib/spring/binstub.rb:11:in' bin / spring:13:require' bin/spring:13:in' bin / rails:3:load' bin/rails:3:in'

0 个答案:

没有答案