The book model is associated with the user via rate (with the rating field).
I want to make it so that when creating a new 'rate', the average value for the book is recalculated and recorded in the "book" field av_rating . I tried this:
def create @new_rate = @book.rates.build(rate_params) @new_rate.user = current_user if @new_rate.save @book.av_rating = Rate.where(book_id: @book.id).average(:rating) redirect_to @book else ... The field remains empty
@book.av_ratingafter save? - Manuk Karapetyan@book, too, must be saved, if changed. - D-side