以下是我在Rails 3中之前的工作的表单:
<%= form_for Style.new do |s| %>
<% end %>
这会引发错误: 未定义的方法`param_key&#39;为零:NilClass
完整跟踪:
NoMethodError - undefined method `param_key' for nil:NilClass:
actionview (4.2.0.rc2) lib/action_view/helpers/form_helper.rb:433:in `form_for'
app/views/styles/_add_style_form.html.erb:1:in `_app_views_styles__add_style_form_html_erb__4060888642586793101_94112200'
actionview (4.2.0.rc2) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.0.rc2) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.0.rc2) lib/action_view/template.rb:143:in `render'
xray-rails (0.1.14) lib/xray/engine.rb:33:in `render_with_xray'
actionview (4.2.0.rc2) lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
actionview (4.2.0.rc2) lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
actionview (4.2.0.rc2) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.0.rc2) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.0.rc2) lib/action_view/renderer/partial_renderer.rb:309:in `render'
actionview (4.2.0.rc2) lib/action_view/renderer/renderer.rb:47:in `render_partial'
actionview (4.2.0.rc2) lib/action_view/renderer/renderer.rb:21:in `render'
actionview (4.2.0.rc2) lib/action_view/helpers/rendering_helper.rb:32:in `render'
app/views/styles/create_dashboard.html.erb:5:in `_app_views_styles_create_dashboard_html_erb___865179136945855599_42166680'
actionview (4.2.0.rc2) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.0.rc2) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.0.rc2) lib/action_view/template.rb:143:in `render'
xray-rails (0.1.14) lib/xray/engine.rb:33:in `render_with_xray'
actionview (4.2.0.rc2) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (4.2.0.rc2) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.0.rc2) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.0.rc2) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (4.2.0.rc2) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (4.2.0.rc2) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (4.2.0.rc2) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (4.2.0.rc2) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.2.0.rc2) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.2.0.rc2) lib/action_view/rendering.rb:100:in `_render_template'
actionpack (4.2.0.rc2) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.2.0.rc2) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (4.2.0.rc2) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.2.0.rc2) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.0.rc2) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.0.rc2) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.0.rc2) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.2.0.rc2) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/funkdified/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
activesupport (4.2.0.rc2) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.0.rc2) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.2.0.rc2) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.2.0.rc2) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
sunspot_rails (2.1.1) lib/sunspot/rails/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (4.2.0.rc2) lib/action_controller/metal/instrumentation.rb:40:in `render'
wicked_pdf (0.11.0) lib/wicked_pdf/pdf_helper.rb:23:in `render_with_wicked_pdf'
actionpack (4.2.0.rc2) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.2.0.rc2) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.2.0.rc2) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0.rc2) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0.rc2) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0.rc2) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0.rc2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0.rc2) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.rc2) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0.rc2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0.rc2) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0.rc2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0.rc2) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0.rc2) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0.rc2) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0.rc2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0.rc2) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0.rc2) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0.rc2) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0.rc2) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0.rc2) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0.rc2) lib/action_dispatch/routing/route_set.rb:802:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
xray-rails (0.1.14) lib/xray/middleware.rb:37:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
meta_request (0.3.3) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack-contrib (1.1.0) lib/rack/contrib/response_headers.rb:17:in `call'
meta_request (0.3.3) lib/meta_request/middlewares/headers.rb:16:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
meta_request (0.3.3) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/rack/error_collector.rb:50:in `traced_call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/rack/agent_hooks.rb:26:in `traced_call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/rack/browser_monitoring.rb:19:in `traced_call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/rack/developer_mode.rb:48:in `traced_call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55: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'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.6.0.beta2) lib/rack/etag.rb:24:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.6.0.beta2) lib/rack/conditionalget.rb:25:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.6.0.beta2) lib/rack/head.rb:13:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/flash.rb:260:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.6.0.beta2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0.beta2) lib/rack/session/abstract/id.rb:220:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/cookies.rb:560:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activerecord (4.2.0.rc2) lib/active_record/query_cache.rb:36:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activerecord (4.2.0.rc2) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/reloader.rb:73:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
railties (4.2.0.rc2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0.rc2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0.rc2) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0.rc2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0.rc2) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0.rc2) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.0.3) lib/quiet_assets.rb:23:in `call_with_quiet_assets'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.6.0.beta2) lib/rack/methodoverride.rb:22:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.6.0.beta2) lib/rack/runtime.rb:18:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activesupport (4.2.0.rc2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.6.0.beta2) lib/rack/lock.rb:17:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.2.0.rc2) lib/action_dispatch/middleware/static.rb:113:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.6.0.beta2) lib/rack/sendfile.rb:113:in `call'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
railties (4.2.0.rc2) lib/rails/engine.rb:518:in `call'
railties (4.2.0.rc2) lib/rails/application.rb:164:in `call'
railties (4.2.0.rc2) lib/rails/railtie.rb:194:in `method_missing'
newrelic_rpm (3.9.0.229) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.6.0.beta2) lib/rack/content_length.rb:15:in `call'
thin (1.6.2) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.2) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.2) lib/thin/connection.rb:53:in `process'
thin (1.6.2) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.6.2) lib/thin/backends/base.rb:73:in `start'
thin (1.6.2) lib/thin/server.rb:162:in `start'
rack (1.6.0.beta2) lib/rack/handler/thin.rb:19:in `run'
rack (1.6.0.beta2) lib/rack/server.rb:286:in `start'
railties (4.2.0.rc2) lib/rails/commands/server.rb:80:in `start'
railties (4.2.0.rc2) lib/rails/commands/commands_tasks.rb:80:in `block in server'
railties (4.2.0.rc2) lib/rails/commands/commands_tasks.rb:75:in `server'
railties (4.2.0.rc2) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
railties (4.2.0.rc2) lib/rails/commands.rb:17:in `<top (required)>'
script/rails:6:in `<main>'
答案 0 :(得分:6)
正如您所提到的,在这种情况下,您的关联belongs_to :model
似乎正在创建一个名为model_name
的方法,该方法干扰了FormBuilder,找出了预期的model_name
。
我在尝试使用fields_for @my_object
时也看到了相同的错误(@my_object
没有回复model_name
或param_key
)。
在我的情况下,我修复了错误:
class MyObject
extend ActiveModel::Naming
end
由Rails 4.x中的form_for
和fields_for
使用