[英]How can I create relationships in multiple tables on rails?
I'm new to rails and learning relationship between tables.我是导轨和表格之间的学习关系的新手。 This is what I want to create.
这就是我想要创造的。 Users wont be able to post into classes or videos just add them to their table.
用户将无法发布到课程或视频中,只需将它们添加到他们的表格中即可。
example: I'm a student and I sign up for a user account.例如:我是一名学生,我注册了一个用户帐户。 Then I choose the classes I want HTML and CSS.
然后我选择我想要的 HTML 和 CSS 类。 And then I'm only able to watch the videos inside those classes.
然后我只能观看这些课程中的视频。
Users->classes->videos
(USERS)
username
password
classes - signs up for multiple classes
(classes)
HTML
CSS
Javascript
PHP
(inside of each class theres videos)
video1
video2
video3
Your relationship should be like has_many
你的关系应该像
has_many
User.rb
has_many :classes
has_many :videos, through: classes
Class.rb
has_many :videos
belongs_to :user
Video.rb
belongs_to :class
belongs_to :user
To apply this associations automatically you can use nested form structure要自动应用此关联,您可以使用嵌套表单结构
Here is link for that.这是链接。
https://github.com/ryanb/nested_form https://github.com/ryanb/nested_form
http://railscasts.com/episodes/196-nested-model-form-revised?view=comments http://railscasts.com/episodes/196-nested-model-form-revised?view=comments
Thanks谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.