【发布时间】:2015-09-21 20:26:31
【问题描述】:
在我的应用程序中,我有一个图书模型的图书索引页。把它想象成一个图书馆。
现在我有由列表组成的董事会。假设我有一个名为 Categories 的板。
所以我去了分类委员会。在我的网址中是 www.example.com/board/1
在这个类别板上有很多列表。假设我有一个名为编程书籍的列表。
所以现在我需要将书籍添加到这个名为 Programming Books 的列表中。
我已经完成了所有设置,只是不知道如何将书籍添加到列表中。当我单击添加书籍时,我如何获得该 list_id?我希望能够单击添加书籍,然后转到列出所有书籍的页面。然后我想通过检查每一本书来选择书籍,然后将它们添加到列表中。
不用担心创建列表或看板我已经正确设置了我只是想将书籍添加到列表中。
类别板 (www.example.com/board/1)
=================== ===================
=Programming Books= =Adventure Books =
=================== ===================
= Book 1 = = add books =
= Book 2 = = =
= Book 3 = = =
= add books = = =
=================== ===================
列表模型
belongs_to :user, inverse_of: :list
has_many :list_books
has_many :books, through: :list_books
accepts_nested_attributes_for :list_books, :allow_destroy => true
List_Books 模型
belongs_to :list
belongs_to :books
图书模型
belongs_to :user, inverse_of: :books
has_many :list_books
has_many :lists, through: :list_books
accepts_nested_attributes_for :list_books, :allow_destroy => true
列表控制器
def addbooks
// Not sure what to put here? It needs to grab the list_id from the list where i clicked add books.
end
private
def_params
// Not sure what params i need
end
添加图书视图
// i need of list of all the books here. Then i want to check each book i want and then submit.
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 has-many-through has-many