1

当 Active Admin 应该在我的表单视图上寻找警报时,它似乎正在寻找用户。我目前得到错误。

 undefined method `body' for #<User:0x007fe21a4afb60> 

以下是 admin/alerts.rb 的内容

ActiveAdmin.register Alert do
  index do
    column :from, :sortable => :from  do |alert|
      div :class => "alert" do
        User.all[alert.from.to_i].name
      end
    end
    column :severity
    column :target
    column :created_at
    column :updated_at
    column "" do |alert|
      links = ''.html_safe
      links += link_to 'Edit', edit_admin_alert_path(alert)
      links += " "
      links += link_to I18n.t('active_admin.delete'), admin_alert_path(alert), :method =>:delete, :confirm => I18n.t('active_admin.delete_confirmation'), :class => "alerts_link delete_link"
    end
  end

  filter :from
  filter :severity
  filter :target

  form do |f|                         
    f.inputs "Alert Details" do       
      f.input :body                  
      f.input :alert_radius              
      f.input :severity
      f.input :target
      f.input :expires_on 
    end                               
    f.actions                         
  end     
end

为方便起见,我还包括了我的终端输出。

Started GET "/admin/alerts/6/edit" for 127.0.0.1 at 2013-06-29 11:18:49 -0600
Processing by Admin::AlertsController#edit as HTML
  Parameters: {"id"=>"6"}
  AdminUser Load (0.2ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 LIMIT 1
  Alert Load (0.1ms)  SELECT "alerts".* FROM "alerts" WHERE "alerts"."id" = ? LIMIT 1  [["id", "6"]]
  Alert Load (0.1ms)  SELECT "alerts".* FROM "alerts" WHERE "alerts"."id" = 6 LIMIT 1
  Rendered /Users/alecwesterman/.rvm/gems/ruby-2.0.0-p0@c911/gems/activeadmin-0.6.0/app/views/active_admin/resource/edit.html.arb (31.8ms)
Completed 500 Internal Server Error in 36ms

NoMethodError - undefined method `body' for #<User:0x007fe21a61df38>:
  activemodel (3.2.11) lib/active_model/attribute_methods.rb:407:in `method_missing'
  activerecord (3.2.11) lib/active_record/attribute_methods.rb:149:in `method_missing'
  actionpack (3.2.11) lib/action_view/helpers/form_helper.rb:1161:in `value_before_type_cast'
  actionpack (3.2.11) lib/action_view/helpers/form_helper.rb:1149:in `value_before_type_cast'
  actionpack (3.2.11) lib/action_view/helpers/form_helper.rb:1043:in `block in to_input_field_tag'
  actionpack (3.2.11) lib/action_view/helpers/form_helper.rb:1043:in `to_input_field_tag'
  actionpack (3.2.11) lib/action_view/helpers/form_helper.rb:692:in `text_field'
  actionpack (3.2.11) 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.11) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
  actionpack (3.2.11) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
  haml (4.0.3) lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
  actionpack (3.2.11) lib/action_view/helpers/capture_helper.rb:40:in `capture'
  haml (4.0.3) 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.6.0) lib/active_admin/form_builder.rb:19:in `block in input'
  activeadmin (0.6.0) lib/active_admin/form_builder.rb:166:in `with_new_form_buffer'
  activeadmin (0.6.0) lib/active_admin/form_builder.rb:19:in `input'
  app/admin/alerts.rb:30:in `block (3 levels) in <top (required)>'
  activeadmin (0.6.0) lib/active_admin/form_builder.rb:159:in `block in field_set_and_list_wrapping'
  actionpack (3.2.11) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
  actionpack (3.2.11) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
  haml (4.0.3) lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
  actionpack (3.2.11) lib/action_view/helpers/capture_helper.rb:40:in `capture'
  haml (4.0.3) 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'
  activeadmin (0.6.0) lib/active_admin/form_builder.rb:159:in `field_set_and_list_wrapping'
  formtastic (2.2.1) lib/formtastic/helpers/inputs_helper.rb:292:in `inputs'
  activeadmin (0.6.0) lib/active_admin/form_builder.rb:13:in `block in inputs'
  activeadmin (0.6.0) lib/active_admin/form_builder.rb:166:in `with_new_form_buffer'
  activeadmin (0.6.0) lib/active_admin/form_builder.rb:13:in `inputs'
  app/admin/alerts.rb:29:in `block (2 levels) in <top (required)>'
  activeadmin (0.6.0) lib/active_admin/views/pages/form.rb:23:in `block in main_content'
  actionpack (3.2.11) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
  actionpack (3.2.11) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
  haml (4.0.3) lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
  actionpack (3.2.11) lib/action_view/helpers/capture_helper.rb:40:in `capture'
  haml (4.0.3) lib/haml/helpers/action_view_mods.rb:59:in `capture_with_haml'
  actionpack (3.2.11) lib/action_view/helpers/form_helper.rb:607:in `fields_for'
  actionpack (3.2.11) lib/action_view/helpers/form_helper.rb:378:in `form_for'
  haml (4.0.3) lib/haml/helpers/action_view_mods.rb:146:in `form_for_with_haml'
  haml (4.0.3) 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.6.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.6.0) lib/active_admin/views/pages/form.rb:22:in `main_content'
  activeadmin (0.6.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:14:in `div'
  activeadmin (0.6.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:14:in `div'
  activeadmin (0.6.0) lib/active_admin/views/pages/base.rb:76:in `build_main_content_wrapper'
  activeadmin (0.6.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:14:in `div'
  activeadmin (0.6.0) lib/active_admin/views/pages/base.rb:59:in `build_page_content'
  activeadmin (0.6.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:14:in `div'
  activeadmin (0.6.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.6.0) lib/active_admin/views/pages/base.rb:38:in `build_page'
  activeadmin (0.6.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.6.0) app/views/active_admin/resource/edit.html.arb:1:in `block in ___sers_alecwesterman__rvm_gems_ruby_______p__c____gems_activeadmin_______app_views_active_admin_resource_edit_html_arb__3034960771782989831_70304341949860'
  arbre (1.0.1) lib/arbre/context.rb:45:in `initialize'
  activeadmin (0.6.0) app/views/active_admin/resource/edit.html.arb:1:in `___sers_alecwesterman__rvm_gems_ruby_______p__c____gems_activeadmin_______app_views_active_admin_resource_edit_html_arb__3034960771782989831_70304341949860'
  actionpack (3.2.11) lib/action_view/template.rb:145:in `block in render'
  activesupport (3.2.11) lib/active_support/notifications.rb:125:in `instrument'
  actionpack (3.2.11) lib/action_view/template.rb:143:in `render'
  actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
  actionpack (3.2.11) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
  activesupport (3.2.11) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.11) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
  actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
  actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
  actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
  actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:18:in `render'
  actionpack (3.2.11) lib/action_view/renderer/renderer.rb:36:in `render_template'
  actionpack (3.2.11) lib/action_view/renderer/renderer.rb:17:in `render'
  actionpack (3.2.11) lib/abstract_controller/rendering.rb:110:in `_render_template'
  actionpack (3.2.11) lib/action_controller/metal/streaming.rb:225:in `_render_template'
  actionpack (3.2.11) lib/abstract_controller/rendering.rb:103:in `render_to_body'
  actionpack (3.2.11) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
  actionpack (3.2.11) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
  actionpack (3.2.11) lib/abstract_controller/rendering.rb:88:in `render'
  actionpack (3.2.11) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
  activesupport (3.2.11) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
  /Users/alecwesterman/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
  activesupport (3.2.11) lib/active_support/core_ext/benchmark.rb:5:in `ms'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
  activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:39:in `render'
  activeadmin (0.6.0) lib/active_admin/resource_controller/actions.rb:42:in `block (2 levels) in edit'
  actionpack (3.2.11) lib/action_controller/metal/responder.rb:230:in `default_render'
  actionpack (3.2.11) 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.11) lib/action_controller/metal/responder.rb:153:in `respond'
  actionpack (3.2.11) lib/action_controller/metal/responder.rb:146:in `call'
  actionpack (3.2.11) lib/action_controller/metal/mime_responds.rb:239:in `respond_with'
  inherited_resources (1.4.0) lib/inherited_resources/actions.rb:25:in `edit'
  activeadmin (0.6.0) lib/active_admin/resource_controller/actions.rb:40:in `edit'
  actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (3.2.11) lib/abstract_controller/base.rb:167:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (3.2.11) lib/active_support/callbacks.rb:447:in `_run__2428523339482689520__process_action__3269890394972785139__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.2.11) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
  activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (3.2.11) lib/abstract_controller/base.rb:121:in `process'
  actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'
  actionpack (3.2.11) lib/action_controller/metal.rb:203:in `dispatch'
  actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.2.11) lib/action_controller/metal.rb:246:in `block in action'
  actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (3.2.11) 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 `call'
  actionpack (3.2.11) 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 `call'
  actionpack (3.2.11) 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.11) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.11) 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.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.11)                   lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__753116613107400990__call__1952201009628989192__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
  quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
  actionpack (3.2.11) 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.11) 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.11) lib/action_dispatch/middleware/static.rb:62:in `call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
  rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
  rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
  rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
  railties (3.2.11) lib/rails/engine.rb:479:in `call'
  railties (3.2.11) lib/rails/application.rb:223:in `call'
  rack (1.4.5) lib/rack/content_length.rb:14:in `call'
  railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
  /Users/alecwesterman/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
  /Users/alecwesterman/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
  /Users/alecwesterman/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

任何想法或反馈将不胜感激。

谢谢。

4

0 回答 0