我有几个小ROR“大多是静态的”类网站和我工作的更深层次的东西一点点,我没有用太多的经验...的Ruby on Rails应用程序使用多个模型
大图片命名。 帐户有许多用户和项目。用户有很多项目。用户添加很多文件和笔记到项目中......
最后我需要生成一个视图,用户可以在其中看到他们的项目,文件,&笔记。以类似于一个下面的手动创建的“概念证明”列表或表格:
Project1
Notes
note1
note2
note3
Files
file1
file2
file2
Users
user1
user2
Project2
Notes
note1
note2
note3
Files
file1
file2
file2
Users
user1
user2
上面会使用某种for循环的嵌入红宝石来产生列表但在此之前,我到我需要确保我有适当的模型关联和调用。
我试图从我所有的表中没有外键,但我一直在与多模式最佳实践混淆。没有外键我想我需要一个连接表,它可以是一个使用“model1_model2”命名约定?和“:through”模型关系的模型?
我的模型现在(这已经改变了很多)有:
帐户:
class Account < ActiveRecord::Base
has_many :projects
has_many :users
末
用户:
class User < ActiveRecord::Base
has_one :account
has_many :projects, :through => :accounts
has_many :dataFiles, :through => :projects
has_many :notes, :through => :projects
末
项目:
class Project < ActiveRecord::Base
belongs_to :account
has_many :users
has_many :datafiles
has_many :notes
末
数据文件:
class DataFile < ActiveRecord::Base
belongs_to :projects
belongs_to :users
末
注:
class Note < ActiveRecord::Base
belongs_to :project
belongs_to :users
末
正如你所看到的;我很困惑!我已经完成了一系列教程并阅读了一本书;这是我的第一个真正的世界应用程序,不只是主要是静态页面... ...
似乎有很多方法可以做到这一点。我想我正在寻找一些关于我应该使用什么模型以及如何连接它们的专家指导。
任何方向或建议,你可以提供非常感谢。谢谢!
这非常有帮助!感谢您的指导。 – twinturbotom