Monthly Archives: June 2012

Rails namespaced models NameError uninitialized constant

I’m using rails v3.2.3

Using namespaced models, you should specify full class names for database associations to avoid this error.

eg

class Assets::Resource < ActiveRecord::Base
  has_many :assets_resource_users, :class_name => “::Assets::ResourceUser”
end

class Assets::ResourceUser < ActiveRecord::Base
  belongs_to :asset_resource, :class_name => “::Assets::Resource”
end

Put :: at the beginning to specify the namespace from the root.

Also, you should set the foreign key on your associations, or rails gets confused.  For example, if you set up resource:references in the migration to create the ResourceUser above, it will create a column “resource_id”, but rails looks for “assets_resource_id” by default.

Adding a new sudo user to CentOs

Our new user will be called batman:

  1. groupadd admins
  2. adduser batman -G admins
  3. passwd batman
  4. visudo (this will open sudoers file in vim)
  5. Add this to the file:
    %admins     ALL=(ALL)     ALL

Any users in the group called ‘admins’ will be sudoers.  So additional users just need to be added to this group.