Rail 5.2
datatables
In my views/books/index.html.slim, I am loading a partial, from another MVC, as follows:
= render partial: 'authors/index', :locals => {:author => @book.author}
In my views/authors/_index.html, I have the following:
.....
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'},
]
});
And, in my controllers/authors_controllers.rb, I have the following:
def index
@authors = Author.where(author: "John Doe")
render json: { data: @authors }
end
When I run it, the authors table displays properly. The problem, is that the author name is hard coded in the controller action. My _index partial, is receiving the author name, but how do I get it to the authors controller, as part of the Ajax call I am making? New to Ajax/Javascript.