我刚刚安装了 ActiveAdmin 来管理我的用户
rails generate active_admin:install --skip-users
rails generate active_admin:resource User
为了使用我与 Devise 一起使用的现有用户模型。
我在初始化程序 active_admin.rb 中的配置是:
ActiveAdmin.setup do |config|
config.authentication_method = :authenticate_admin_user!
config.current_user_method = :current_user
config.logout_link_path = :destroy_user_session_path
config.logout_link_method = :delete
config.allow_comments = false
config.batch_actions = true
end
身份验证方法在我的 application_controller.rb 中:
def authenticate_admin_user!
redirect_to new_user_session_path unless current_user.try(:is_admin?)
end
在 routes.rb 我有:
devise_for :users
ActiveAdmin.routes(self)
我可以访问索引,但是当我想编辑用户或创建新用户时它会中断。这是bstacktrace:
Started GET "/admin/users/new" for 127.0.0.1 at 2013-04-26 14:45:38 +0800
Processing by Admin::UsersController#new as HTML
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 20 LIMIT 1
User Load (1.1ms) SELECT "users".* FROM "users"
Rendered /home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.6.0/app/views/active_admin/resource/new.html.arb (426.2ms)
Completed 500 Internal Server Error in 440ms
ActionView::Template::Error (undefined method `user_id' for #<User:0x007ff5f522fdb0>):
1: insert_tag renderer_for(:new)
activemodel (3.2.13) lib/active_model/attribute_methods.rb:407:in `method_missing'
activerecord (3.2.13) lib/active_record/attribute_methods.rb:149:in `method_missing'
actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1152:in `value'
actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:1143:in `value'
actionpack (3.2.13) lib/action_view/helpers/form_options_helper.rb:580:in `to_select_tag'
actionpack (3.2.13) lib/action_view/helpers/form_options_helper.rb:157:in `select'
actionpack (3.2.13) lib/action_view/helpers/form_options_helper.rb:642:in `select'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/formtastic-2.2.1/lib/formtastic/inputs/select_input.rb:154:in `select_html'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/formtastic-2.2.1/lib/formtastic/inputs/select_input.rb:149:in `block in to_html'
actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
haml (4.0.2) lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `capture'
haml (4.0.2) lib/haml/helpers/action_view_mods.rb:59:in `capture_with_haml'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/formtastic-2.2.1/lib/formtastic/inputs/base/wrapping.rb:11:in `input_wrapping'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/formtastic-2.2.1/lib/formtastic/inputs/select_input.rb:146: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'
formtastic (2.2.1) lib/formtastic/helpers/inputs_helper.rb:329:in `block in fieldset_contents_from_column_list'
formtastic (2.2.1) lib/formtastic/helpers/inputs_helper.rb:317:in `collect'
formtastic (2.2.1) lib/formtastic/helpers/inputs_helper.rb:317:in `fieldset_contents_from_column_list'
formtastic (2.2.1) lib/formtastic/helpers/inputs_helper.rb:296: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'
activeadmin (0.6.0) lib/active_admin/views/pages/form.rb:43:in `block in default_form_config'
activeadmin (0.6.0) lib/active_admin/views/pages/form.rb:23:in `instance_exec'
activeadmin (0.6.0) lib/active_admin/views/pages/form.rb:23:in `block in main_content'
actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
haml (4.0.2) lib/haml/helpers/action_view_xss_mods.rb:5:in `with_output_buffer_with_haml_xss'
actionpack (3.2.13) lib/action_view/helpers/capture_helper.rb:40:in `capture'
haml (4.0.2) lib/haml/helpers/action_view_mods.rb:59:in `capture_with_haml'
actionpack (3.2.13) lib/action_view/helpers/form_helper.rb:378:in `form_for'
haml (4.0.2) lib/haml/helpers/action_view_mods.rb:146:in `form_for_with_haml'
haml (4.0.2) lib/haml/helpers/action_view_xss_mods.rb:28:in `form_for_with_haml_xss'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/formtastic-2.2.1/lib/formtastic/helpers/form_helper.rb:161:in `block in semantic_form_for'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/formtastic-2.2.1/lib/formtastic/helpers/form_helper.rb:192:in `with_custom_field_error_proc'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/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:18: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:18: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:18: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:18: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'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.6.0/app/views/active_admin/resource/new.html.arb:1:in `block in __home_flashgordon__rvm_gems_ruby_______p____gems_activeadmin_______app_views_active_admin_resource_new_html_arb__4493823286655400845_61452940'
arbre (1.0.1) lib/arbre/context.rb:45:in `instance_eval'
arbre (1.0.1) lib/arbre/context.rb:45:in `initialize'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.6.0/app/views/active_admin/resource/new.html.arb:1:in `new'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.6.0/app/views/active_admin/resource/new.html.arb:1:in `__home_flashgordon__rvm_gems_ruby_______p____gems_activeadmin_______app_views_active_admin_resource_new_html_arb__4493823286655400845_61452940'
actionpack (3.2.13) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.13) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.13) lib/action_view/template.rb:143:in `render'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.13) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.13) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.13) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.13) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.13) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/flashgordon/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
sunspot_rails (1.3.3) lib/sunspot/rails/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:39:in `render'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.6.0/lib/active_admin/resource_controller/actions.rb:34:in `block (2 levels) in new'
actionpack (3.2.13) lib/action_controller/metal/responder.rb:230:in `call'
actionpack (3.2.13) lib/action_controller/metal/responder.rb:230:in `default_render'
actionpack (3.2.13) 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.13) lib/action_controller/metal/responder.rb:153:in `respond'
actionpack (3.2.13) lib/action_controller/metal/responder.rb:146:in `call'
actionpack (3.2.13) lib/action_controller/metal/mime_responds.rb:239:in `respond_with'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/inherited_resources-1.4.0/lib/inherited_resources/actions.rb:19:in `new'
/home/flashgordon/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.6.0/lib/active_admin/resource_controller/actions.rb:32:in `new'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.13) lib/active_support/callbacks.rb:480:in `_run__2693105796829942473__process_action__3316774578101385478__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.13) 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.13) lib/action_dispatch/routing/route_set.rb:612: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.13) 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.13) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.13) 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.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__2837449993009062074__call__316444418893315790__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.13) 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.13) 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.13) lib/action_dispatch/middleware/static.rb:63:in `call'
railties (3.2.13) lib/rails/engine.rb:479:in `call'
railties (3.2.13) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
puma (1.6.3) lib/puma/server.rb:412:in `handle_request'
puma (1.6.3) lib/puma/server.rb:306:in `process_client'
puma (1.6.3) lib/puma/server.rb:215:in `block in run'
puma (1.6.3) lib/puma/thread_pool.rb:94:in `call'
puma (1.6.3) lib/puma/thread_pool.rb:94:in `block in spawn_thread'
Rendered /home/flashgordon/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.9ms)
Rendered /home/flashgordon/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.7ms)
Rendered /home/flashgordon/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (20.2ms)
任何帮助都是极好的 :)
提前致谢