[英]Models/Controllers in subfolders for rails?
I'm trying to keep the application as neat and tidy as possible because it could get quite large. 我正在尝试使应用程序尽可能整洁,因为它可能会变得很大。 Already a few days into it I've noticed the following pattern in the models: 几天之后,我注意到模型中的以下模式:
models/
prefix_file.rb
prefix_file2.rb
prefix_file3.rb
file.rb
prefix2_file.rb
prefix2_file2.rb
Is there anyway to organise the models directory into subfolders? 无论如何,有没有将models目录组织到子文件夹中?
You can namespace your files in directories and use modules. 您可以在目录中命名文件并使用模块。
For example 例如
models/
prefix/
file.rb
file2.rb
file3.rb
prefix2/
file.rb
file2.rb
file.rb
Then inside your files within the directories you would have something like 然后在目录内的文件中,您将看到
models/prefix/file.rb 型号/前缀/file.rb
module Prefix
class File < ActiveRecord::Base
end
end
To use them you would need to have code like this Prefix::File.some_method
要使用它们,您需要具有类似Prefix::File.some_method
代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.