2013-04-25 211 views
0

我正在使用ActiveAdmin框架,我跟着ActiveAdmin的入門,並在最後一步rails generate active_admin:resource [MyModelName]我寫這個:rails generate active_admin:resource User然後我試着在瀏覽器中看到結果,所以我運行服務器rails s,然後我得到這個問題:運行軌服務器命令

[email protected]:~/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/[email protected]/gems/activeadmin-0.6.0/lib/active_admin/application.rb:179:in 
`block in load!' from 
/home/edu/.rvm/gems/[email protected]/gems/activeadmin-0.6.0/lib/active_admin/application.rb:179:in 
`each'  from 
/home/edu/.rvm/gems/[email protected]/gems/activeadmin-0.6.0/lib/active_admin/application.rb:179:in 
`load!' from 
/home/edu/.rvm/gems/[email protected]/gems/activeadmin-0.6.0/lib/active_admin/application.rb:197:in 
`routes' from 
/home/edu/.rvm/gems/[email protected]/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/[email protected]/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in 
`instance_exec' from 
/home/edu/.rvm/gems/[email protected]/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:289:in 
`eval_block' from 
/home/edu/.rvm/gems/[email protected]/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/[email protected]/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:in 
`block in load_paths' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:in 
`each'  from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:40:in 
`load_paths' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/application/routes_reloader.rb:16:in 
`reload!' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/application.rb:108:in `reload_routes!' from 
/home/edu/.rvm/gems/[email protected]/gems/activeadmin-0.6.0/lib/active_admin/reloader.rb:34:in 
`reload!' from 
/home/edu/.rvm/gems/[email protected]/gems/activeadmin-0.6.0/lib/active_admin/reloader.rb:61:in 
`block in attach!'  from 
/home/edu/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:429:in 
`_run__246534365__prepare__874865436__callbacks' from 
/home/edu/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in 
`__run_callback' from 
/home/edu/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in 
`_run_prepare_callbacks' from 
/home/edu/.rvm/gems/[email protected]/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in 
`run_callbacks' from 
/home/edu/.rvm/gems/[email protected]/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:74:in 
`prepare!'  from 
/home/edu/.rvm/gems/[email protected]/gems/actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:48:in 
`prepare!'  from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/application/finisher.rb:47:in 
`block in <module:Finisher>' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'  from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'  from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!' from 
/home/edu/.rvm/gems/[email protected]/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/[email protected]/gems/rack-1.4.5/lib/rack/builder.rb:51:in 
`instance_eval' from 
/home/edu/.rvm/gems/[email protected]/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/[email protected]/gems/rack-1.4.5/lib/rack/builder.rb:40:in 
`eval'  from 
/home/edu/.rvm/gems/[email protected]/gems/rack-1.4.5/lib/rack/builder.rb:40:in 
`parse_file' from 
/home/edu/.rvm/gems/[email protected]/gems/rack-1.4.5/lib/rack/server.rb:200:in 
`app' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/commands/server.rb:46:in `app' from 
/home/edu/.rvm/gems/[email protected]/gems/rack-1.4.5/lib/rack/server.rb:304:in 
`wrapped_app' from 
/home/edu/.rvm/gems/[email protected]/gems/rack-1.4.5/lib/rack/server.rb:254:in 
`start' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/commands/server.rb:70:in `start' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/commands.rb:55:in 
`block in <top (required)>' from 
/home/edu/.rvm/gems/[email protected]/gems/railties-3.2.13/lib/rails/commands.rb:50:in 
`tap' from 
/home/edu/.rvm/gems/[email protected]/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>' 

有人知道如何解決它或什麼是錯的。

+2

你確定,你做了捆綁exec rake db:migrate'嗎? – kiddorails 2013-04-25 23:16:58

+0

我這樣做,我得到這個:耙子中止!未初始化的常量用戶 – edudepetris 2013-04-25 23:47:43

+0

您試圖正確運行服務器的IP /端口? – jmstone617 2013-04-26 02:27:13

回答

0

您遇到的問題是 - ActiveAdmin試圖在users上生成資源,但users的模型不存在。因此,在用戶上生成active_admin資源之前,必須先創建一個User模型。

做它,如下所示:

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 

讓我知道,如果它可以幫助你。評論你遇到的錯誤。

祝你好運

+0

感謝您的幫助! 問題是我的項目中沒有用戶模型:P。 – edudepetris 2013-04-26 14:01:15

+0

是的。這就是爲什麼,生成模型解決了這個問題。 :) – kiddorails 2013-04-26 19:10:42