1

我正在使用 ActiveAdmin 框架,我遵循 ActiveAdmin 的入门,在最后一步中rails generate active_admin:resource [MyModelName]我写了这个:rails generate active_admin:resource User然后我尝试在浏览器中查看结果,所以我运行服务器rails s,然后我遇到了这个问题:

 edu@edu-ThinkPad-Edge:~/Desktop/rails_proyects/fulbo$ rails server
 => Booting WEBrick
 => Rails 3.2.13 application starting in development on `http://0.0.0.0:3000`
 => Call with -d to detach
 => Ctrl-C to shutdown server Exiting /home/edu/Desktop/rails_proyects/fulbo/app/admin/users.rb:1:in `<top
 (required)>': uninitialized constant User (NameError)  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activeadmin-0.6.0/lib/active_admin/application.rb:179:in
 `block in load!'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activeadmin-0.6.0/lib/active_admin/application.rb:179:in
 `each'     from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activeadmin-0.6.0/lib/active_admin/application.rb:179:in
 `load!'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activeadmin-0.6.0/lib/active_admin/application.rb:197:in
 `routes'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activeadmin-0.6.0/lib/active_admin.rb:83:in
 `routes'   from
 /home/edu/Desktop/rails_proyects/fulbo/config/routes.rb:3:in `block in
 <top (required)>'  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in
 `instance_exec'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in
 `eval_block'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:267:in
 `draw'     from
 /home/edu/Desktop/rails_proyects/fulbo/config/routes.rb:1:in `<top
 (required)>'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:in
 `block in load_paths'  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:in
 `each'     from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:in
 `load_paths'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:16:in
 `reload!'  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/application.rb:108:in `reload_routes!'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activeadmin-0.6.0/lib/active_admin/reloader.rb:34:in
 `reload!'  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activeadmin-0.6.0/lib/active_admin/reloader.rb:61:in
 `block in attach!'     from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:429:in
 `_run__246534365__prepare__874865436__callbacks'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in
 `__run_callback'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in
 `_run_prepare_callbacks'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in
 `run_callbacks'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:74:in
 `prepare!'     from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:48:in
 `prepare!'     from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/application/finisher.rb:47:in
 `block in <module:Finisher>'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'     from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'     from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in
 `method_missing'   from
 /home/edu/Desktop/rails_proyects/fulbo/config/environment.rb:5:in
 `<top (required)>'     from
 /home/edu/Desktop/rails_proyects/fulbo/config.ru:3:in `block in
 <main>'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/rack-1.4.5/lib/rack/builder.rb:51:in
 `instance_eval'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/rack-1.4.5/lib/rack/builder.rb:51:in
 `initialize'   from /home/edu/Desktop/rails_proyects/fulbo/config.ru:in
 `new'  from /home/edu/Desktop/rails_proyects/fulbo/config.ru:in
 `<main>'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/rack-1.4.5/lib/rack/builder.rb:40:in
 `eval'     from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/rack-1.4.5/lib/rack/builder.rb:40:in
 `parse_file'   from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/rack-1.4.5/lib/rack/server.rb:200:in
 `app'  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in `app'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/rack-1.4.5/lib/rack/server.rb:304:in
 `wrapped_app'  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/rack-1.4.5/lib/rack/server.rb:254:in
 `start'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start'  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/commands.rb:55:in
 `block in <top (required)>'    from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/commands.rb:50:in
 `tap'  from
 /home/edu/.rvm/gems/ruby-1.9.3-p392@fulbo/gems/railties-3.2.13/lib/rails/commands.rb:50:in
 `<top (required)>'     from script/rails:6:in `require'    from
 script/rails:6:in `<main>'

有人知道如何解决它或出了什么问题。

4

1 回答 1

1

您遇到的问题是 - ActiveAdmin 正在尝试在 上生成资源users,但模型users不存在。因此,您必须先创建一个模型User,然后才能在 User 上生成 active_admin 资源。

执行以下操作:

rm app/admin/users.rb
rails generate model User username: string email: string
bundle exec rake db:migrate
#this should be successful
rails generate active_admin:resource User
rails server

让我知道,如果它帮助你。评论您遇到的错误。

祝你好运

于 2013-04-26T07:32:50.133 回答