我的 RoR 应用程序中有一个模型让我发疯。
我想为其添加一个新属性,但它只是不允许我这样做 这是代码
class Issue < ActiveRecord::Base
attr_accessible :page_count, # -> unexpected parameter value 'page_count'
:publication
....
end
有问题的属性在迁移文件中有相应的字段。
如果我手动添加访问器方法,错误就会消失。
attr_reader :page_count
attr_writer :page_count
def page_count
@page_count
end
def page_count=(value)
@page_count = value
end
问题是,我不明白为什么会发生这种情况,因为我在这个模型类上有许多其他属性并且碰巧没有这个问题。
我正在使用 rails 3.2.9 和 ruby 1.9.3p194(2012-04-20 修订版 35410)[x86_64-darwin11.4.0]
根据要求,这是完整的堆栈跟踪。我正在使用具有大量捆绑宝石的 activeadmin。
activemodel (3.2.9) lib/active_model/attribute_methods.rb:407:in `method_missing'
activerecord (3.2.9) lib/active_record/attribute_methods.rb:149:in `method_missing'
actionpack (3.2.9) lib/action_view/helpers/form_helper.rb:1161:in `value_before_type_cast'
actionpack (3.2.9) lib/action_view/helpers/form_helper.rb:1149:in `value_before_type_cast'
actionpack (3.2.9) lib/action_view/helpers/form_helper.rb:1043:in `block in to_input_field_tag'
actionpack (3.2.9) lib/action_view/helpers/form_helper.rb:1043:in `fetch'
actionpack (3.2.9) lib/action_view/helpers/form_helper.rb:1043:in `to_input_field_tag'
actionpack (3.2.9) lib/action_view/helpers/form_helper.rb:692:in `text_field'
actionpack (3.2.9) lib/action_view/helpers/form_helper.rb:1284:in `text_field'
formtastic (2.2.1) lib/formtastic/inputs/base/stringish.rb:10:in `block in to_html'
actionpack (3.2.9) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.2.9) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
haml (4.0.0) lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
actionpack (3.2.9) lib/action_view/helpers/capture_helper.rb:40:in `capture'
haml (4.0.0) lib/haml/helpers/action_view_mods.rb:59:in `capture_with_haml'
formtastic (2.2.1) lib/formtastic/inputs/base/wrapping.rb:11:in `input_wrapping'
formtastic (2.2.1) lib/formtastic/inputs/base/stringish.rb:8:in `to_html'
formtastic (2.2.1) lib/formtastic/helpers/input_helper.rb:240:in `input'
activeadmin (0.5.0) lib/active_admin/form_builder.rb:22:in `block in input'
activeadmin (0.5.0) lib/active_admin/form_builder.rb:173:in `with_new_form_buffer'
activeadmin (0.5.0) lib/active_admin/form_builder.rb:22:in `input'
app/admin/issues.rb:17:in `block (3 levels) in <top (required)>'
actionpack (3.2.9) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.2.9) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
haml (4.0.0) lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
actionpack (3.2.9) lib/action_view/helpers/capture_helper.rb:40:in `capture'
haml (4.0.0) lib/haml/helpers/action_view_mods.rb:59:in `capture_with_haml'
formtastic (2.2.1) lib/formtastic/helpers/fieldset_wrapper.rb:32:in `field_set_and_list_wrapping'
formtastic (2.2.1) lib/formtastic/helpers/inputs_helper.rb:292:in `inputs'
activeadmin (0.5.0) lib/active_admin/form_builder.rb:14:in `block in inputs'
activeadmin (0.5.0) lib/active_admin/form_builder.rb:173:in `with_new_form_buffer'
activeadmin (0.5.0) lib/active_admin/form_builder.rb:14:in `inputs'
app/admin/issues.rb:13:in `block (2 levels) in <top (required)>'
activeadmin (0.5.0) lib/active_admin/views/pages/form.rb:23:in `instance_exec'
activeadmin (0.5.0) lib/active_admin/views/pages/form.rb:23:in `block in main_content'
actionpack (3.2.9) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.2.9) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
haml (4.0.0) lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
actionpack (3.2.9) lib/action_view/helpers/capture_helper.rb:40:in `capture'
haml (4.0.0) lib/haml/helpers/action_view_mods.rb:59:in `capture_with_haml'
actionpack (3.2.9) lib/action_view/helpers/form_helper.rb:607:in `fields_for'
actionpack (3.2.9) lib/action_view/helpers/form_helper.rb:378:in `form_for'
haml (4.0.0) lib/haml/helpers/action_view_mods.rb:135:in `form_for_with_haml'
haml (4.0.0) lib/haml/helpers/action_view_xss_mods.rb:28:in `form_for_with_haml_xss'
formtastic (2.2.1) lib/formtastic/helpers/form_helper.rb:161:in `block in semantic_form_for'
formtastic (2.2.1) lib/formtastic/helpers/form_helper.rb:192:in `with_custom_field_error_proc'
formtastic (2.2.1) lib/formtastic/helpers/form_helper.rb:160:in `semantic_form_for'
activeadmin (0.5.0) lib/active_admin/view_helpers/form_helper.rb:8:in `active_admin_form_for'
arbre (1.0.1) lib/arbre/element.rb:175:in `method_missing'
activeadmin (0.5.0) lib/active_admin/views/pages/form.rb:22:in `main_content'
activeadmin (0.5.0) lib/active_admin/views/pages/base.rb:78:in `block (2 levels) in build_main_content_wrapper'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `div'
activeadmin (0.5.0) lib/active_admin/views/pages/base.rb:77:in `block in build_main_content_wrapper'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `div'
activeadmin (0.5.0) lib/active_admin/views/pages/base.rb:76:in `build_main_content_wrapper'
activeadmin (0.5.0) lib/active_admin/views/pages/base.rb:60:in `block in build_page_content'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `div'
activeadmin (0.5.0) lib/active_admin/views/pages/base.rb:59:in `build_page_content'
activeadmin (0.5.0) lib/active_admin/views/pages/base.rb:42:in `block (2 levels) in build_page'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:18:in `div'
activeadmin (0.5.0) lib/active_admin/views/pages/base.rb:39:in `block in build_page'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
activeadmin (0.5.0) lib/active_admin/views/pages/base.rb:38:in `build_page'
activeadmin (0.5.0) lib/active_admin/views/pages/base.rb:10:in `build'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:30:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
activeadmin (0.5.0) app/views/active_admin/resource/new.html.arb:1:in `block in ___sers_franciscogindre__rvm_gems_ruby_______p____gems_activeadmin_______app_views_active_admin_resource_new_html_arb__4355196806900018113_70233184752180'
arbre (1.0.1) lib/arbre/context.rb:45:in `instance_eval'
arbre (1.0.1) lib/arbre/context.rb:45:in `initialize'
activeadmin (0.5.0) app/views/active_admin/resource/new.html.arb:1:in `new'
activeadmin (0.5.0) app/views/active_admin/resource/new.html.arb:1:in `___sers_franciscogindre__rvm_gems_ruby_______p____gems_activeadmin_______app_views_active_admin_resource_new_html_arb__4355196806900018113_70233184752180'
actionpack (3.2.9) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.9) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.9) lib/action_view/template.rb:143:in `render'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.9) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.9) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.9) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.9) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.9) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.9) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.9) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.9) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.9) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.9) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.9) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.9) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.9) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/franciscogindre/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (3.2.9) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.9) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:39:in `render'
activeadmin (0.5.0) lib/active_admin/resource_controller/actions.rb:34:in `block (2 levels) in new'
actionpack (3.2.9) lib/action_controller/metal/responder.rb:230:in `call'
actionpack (3.2.9) lib/action_controller/metal/responder.rb:230:in `default_render'
actionpack (3.2.9) lib/action_controller/metal/responder.rb:160:in `to_html'
responders (0.9.3) lib/responders/flash_responder.rb:104:in `to_html'
actionpack (3.2.9) lib/action_controller/metal/responder.rb:153:in `respond'
actionpack (3.2.9) lib/action_controller/metal/responder.rb:146:in `call'
actionpack (3.2.9) lib/action_controller/metal/mime_responds.rb:239:in `respond_with'
inherited_resources (1.3.1) lib/inherited_resources/actions.rb:19:in `new'
activeadmin (0.5.0) lib/active_admin/resource_controller/actions.rb:32:in `new'
actionpack (3.2.9) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.9) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.9) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.9) lib/active_support/callbacks.rb:458:in `_run__3461794753324901195__process_action__526321814918135960__callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.9) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.9) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.9) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.9) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.9) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.9) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.9) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.9) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.9) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.9) lib/action_dispatch/routing/route_set.rb:601: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'
actionpack (3.2.9) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.9) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `_run__4545952714989117464__call__1013407512145641246__callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.9) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.9) lib/rails/engine.rb:479:in `call'
railties (3.2.9) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'