请问各位,我的 model 目录里有多级目录比如 models/materiale/oitm.rb models/materiale/ocrd.rb
我需要 ocrd has_many :oitms 这个需要怎么写?我按平常的写法保存数据时报错了 uninitialized constant Oitm
在 config/application.rb 里要加一句
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
/app/models/activity.rb /app/models/category/activity_category.rb
class Activity < ActiveRecord::Base
paginates_per 12
belongs_to :user
belongs_to :category, :class_name => "Category::ActivityCategory"
delegate :name, :description, :to => :category, :prefix => true, :allow_nil => true
mount_uploader :cover, PictureUploader
end
不知道你是怎么写的
另外 ruby-china 源代码中也有
class User
...
has_many :notifications, :class_name => 'Notification::Base', :dependent => :delete
...
end
/app/models/user.rb /app/models/notification/base.rb
是不是命名空间的问题? models/materiale/oitm.rb
要写成
class Materiale::Oitm < ActiveRecord::Base
...
end