Ruby on rails 包含Ruby on Rails内容的播放列表
我想在RubyonRails应用程序中创建一个播放列表概念。目前,我只有一个Ruby on rails 包含Ruby on Rails内容的播放列表,ruby-on-rails,ruby,associations,has-many-through,playlist,Ruby On Rails,Ruby,Associations,Has Many Through,Playlist,我想在RubyonRails应用程序中创建一个播放列表概念。目前,我只有一个内容模型,这就是播放列表中的内容 我已经知道我需要的关联,我正在通过:使用,因为我需要联接表中的order属性,以了解每个播放列表中内容的顺序 class Playlist < ActiveRecord::Base has_many :contents_playlists has_many :contents, through: :contents_playlists end class Cont
内容
模型,这就是播放列表中的内容
我已经知道我需要的关联,我正在通过:使用,因为我需要联接表中的order
属性,以了解每个播放列表中内容的顺序
class Playlist < ActiveRecord::Base
has_many :contents_playlists
has_many :contents, through: :contents_playlists
end
class Content < ActiveRecord::Base
has_many :contents_playlists
has_many :playlists, through: :contents_playlists
end
class ContentsPlaylist < ActiveRecord::Base
belongs_to :content
belongs_to :playlist
end
class Playlist
我的问题是,我不支持RoR,关于这一点,我知道这个理论(已经阅读了Rails指南),但我不能毫无错误地执行它。我想是因为我失去了一些东西
我搜索了一个又一个带有代码的教程和示例,但什么也没找到。因此,我想获得一些帮助:如何将该属性添加到联接表中(我已经使用scaffold
创建了它,但我打赌这不是推荐的…),以及如何管理视图和控制器,为我提供一个界面,以便将内容添加到播放列表中,并查看播放列表中的内容,按照顺序你的名字有很多错,应该是内容播放列表而不是内容播放列表吗
class Playlist < ActiveRecord::Base
has_many :contents_playlists
has_many :contents, through: :contents_playlists
end
class Content < ActiveRecord::Base
has_many :contents_playlists
has_many :playlists, through: :contents_playlists
end
class ContentsPlaylist < ActiveRecord::Base
belongs_to :content
belongs_to :playlist
end
class Playlist < ActiveRecord::Base
has_many :content_playlists
has_many :contents, through: :content_playlists
end
class Content < ActiveRecord::Base
has_many :content_playlists
has_many :playlists, through: :content_playlists
end
class ContentPlaylist < ActiveRecord::Base
belongs_to :content
belongs_to :playlist
end
class Playlist
这是问题中的一个输入错误。谢谢你的注意。我已经编辑了这个问题。您遇到了什么错误?错误发生在我试图构建一个视图来创建一个ContentsPlaylist
表单时,该表单具有content\u id
、playlist\u id
和order
。我猜我真的不知道如何使用order
属性创建ContentsPlaylist
表,我也不知道以后如何使用关联。我的目标是获得一个视图,在该视图中,我可以使用顺序将内容添加到播放列表
(位置)。我做不到。如果它是顺序,那么这里有一个宝石你可以看看:作为列表,我只想内容
s被排序时,他们在一个播放列表。将有多个播放列表,因此。。。我已经看过那一集了,但那不是我想要的。