Rail 5.2
datatables
在我的views/books/index.html.slim 中,我正在从另一个MVC 加载部分内容,如下所示:
= render partial: 'authors/index', :locals => {:author => @book.author}
在我的意见/作者/_index.html 中,我有以下内容:
.....
table.table-striped.table-bordered.table-hover.nowrap#AuthorsIndex.display
.....
javascript:
$('#AuthorsIndex').DataTable({
ajax: '/authors',
columns: [
{title: 'Publish Date', data: 'created_at'},
{title: 'Publisher', data: 'publisher'},
{title: 'Title', data: 'title'},
]
});
而且,在我的 controllers/authors_controllers.rb 中,我有以下内容:
def index
@authors = Author.where(author: "John Doe")
render json: { data: @authors }
end
当我运行它时,作者表正确显示。问题是作者姓名在控制器操作中是硬编码的。我的 _index 部分,正在接收作者姓名,但是作为我正在进行的 Ajax 调用的一部分,我如何将其发送给作者控制器?Ajax/Javascript 新手。