活动管理宝石(名称错误)

时间:2012-10-21 11:27:01

标签: ruby-on-rails activeadmin

我有这个课程。

用户:

class User < ActiveRecord::Base
  attr_accessible :email, :name
  has_many :berichten
end

类别:

class Category < ActiveRecord::Base
  attr_accessible :name
  has_many :berichten
end

Berichten:

class Berichten < ActiveRecord::Base
  attr_accessible :bericht, :user
  belongs_to :user
  belongs_to :category
end

我先做了:rails生成active_admin:资源用户 我看到了这个输出:create app / admin / users.rb

然后我做了:ails生成active_admin:资源类别 我看到了这个输出:

 home/roelof/tamara/tamara_site/app/admin/users.rb:1:in `<top (required)>': uninitialized constant Users (NameError)
    from /home/roelof/.gem/ruby/1.9.1/gems/activeadmin-0.5.0/lib/active_admin/application.rb:182:in `block in load!'
    from /home/roelof/.gem/ruby/1.9.1/gems/activeadmin-0.5.0/lib/active_admin/application.rb:182:in `each'
    from /home/roelof/.gem/ruby/1.9.1/gems/activeadmin-0.5.0/lib/active_admin/application.rb:182:in `load!'
    from /home/roelof/.gem/ruby/1.9.1/gems/activeadmin-0.5.0/lib/active_admin/application.rb:205:in `routes'
    from /home/roelof/.gem/ruby/1.9.1/gems/activeadmin-0.5.0/lib/active_admin.rb:79:in `routes'
    from /home/roelof/tamara/tamara_site/config/routes.rb:2:in `block in <top (required)>'
    from /home/roelof/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
    from /home/roelof/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
    from /home/roelof/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:260:in `draw'
    from /home/roelof/tamara/tamara_site/config/routes.rb:1:in `<top (required)>'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `each'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application.rb:108:in `reload_routes!'
    from /home/roelof/.gem/ruby/1.9.1/gems/activeadmin-0.5.0/lib/active_admin/reloader.rb:34:in `reload!'
    from /home/roelof/.gem/ruby/1.9.1/gems/activeadmin-0.5.0/lib/active_admin/reloader.rb:61:in `block in attach!'
    from /home/roelof/.gem/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:429:in `_run__3584427286517482665__prepare__2286595675940506716__callbacks'
    from /home/roelof/.gem/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
    from /home/roelof/.gem/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
    from /home/roelof/.gem/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /home/roelof/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
    from /home/roelof/.gem/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/roelof/tamara/tamara_site/config/environment.rb:5:in `<top (required)>'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application.rb:103:in `require_environment!'
    from /home/roelof/.gem/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:25:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

如何解决这个问题?

鲁洛夫

1 个答案:

答案 0 :(得分:1)

您应该rails generate active_admin:resource user代替rails generate active_admin:resource users(用户与用户)。

你这样做的方式,active_admin搜索一个Users类,当然不存在。

所以删除app/admin/users.rb并运行上面的命令。