2013-10-25 173 views

回答

1

是它很容易:

结构:

app/ 
    models/ 
    widgets/ 
     user_widget.rb 
    user.rb 

型号:

class Widgets::UserWidget < ActiveRecord::Base 
end 

class User < ActiveRecord::Base 
end 

根据记录,它也适用于该库以同样的方式:

结构:

lib/ 
    dsl/ 
    comments_dsl.rb 
    tasks/ 
    graph.rb 

类:

class Graph 
end 

class DSL::CommentsDSL 
end 
0

你可以有你的模型结构如下所示:

# /app/models/foo.rb 
class Foo < ActiveRecord::Base 
    .. 
    has_many :bars, class_name: Foo::Bar 
end 

# /app/models/foo/bar.rb 
class Foo::Bar < ActiveRecord::Base 
    .. 
    belongs_to :foo 
end 

您可以通过Foo通过Foo::Barfoo访问模型bar。 Rails将自动加载/app/models中的任何文件。所以没有必要的配置。