Rails 5.2
In my views/books/show.html.slim, I have:
.row
= render 'books/menu_items'
.row
.col-lg-6
= render partial: 'books/index', :locals => {books: @books.author_id}
.col-lg-6
= render partial: 'books/comments', :locals => {book_id: @book.id}
(some additional code to draw the page)
In my views/books/_menu_items.html.slim, I have:
button.btn.btn-primary type="button" data-target="#BookComment" data-toggle="modal" data-html="true"
= "Comment On Book"
span#CommentNotice
- if !!flash[:notice]
= flash[:notice]
when the page first loads, the two tables in the partials are populated.
On top of the page, when I click on the Comment On Book button, it activates the following method in the Books Controller:
In my controllers/books_controller.rb, I have:
def create_author_comment
@action = dosomething
respond_to do |format|
if @action
format.js {render :partial => 'books/comments_refresh', :format => :js}
flash.now[:notice] = 'New Comment Recorded'
end
end
And, in books/comments_refresh.js.erb, I have some code that refreshes the books/comments partial, without refreshing the entire page.
When I click on the button, the modal appears, I fill it, and submit, the modal disappears, and the comments table 'books/comments' refreshes instantly, without re-rendering the page, but the success notification does not appear.
Any ideas?