ActiveRecord, excluding recording! =?

I have the following which gives me a list of comments:

@comments = record.commentable.comments
Record

in this case is a comment taken by an observer. What I want to do is get a list of comments, with the exception of the last comment, which in this case is a post.

I tried the following, but with errors

"ActionView :: Template :: Error (invalid number of arguments (0 for 1)):"

@comments = record.commentable.comments.where(:id != record.id)

Suggestions? thank

+3
source share
1 answer
@comments = record.commentable.comments.where('id <> ?' , record.id)

More details here:

+7
source

Source: https://habr.com/ru/post/1779691/


All Articles