Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord, excluding a record !=?

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

@comments = record.commentable.comments

record in this case is a comment captured by an observer. What I want to do is get a list of comments excluding the recent comment, which in this case is record.

I tried the following but it errors with

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

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

Suggestions? thanks

like image 950
AnApprentice Avatar asked May 20 '26 01:05

AnApprentice


1 Answers

@comments = record.commentable.comments.where('id <> ?' , record.id)

More info here:

  • http://asciicasts.com/episodes/215-advanced-queries-in-rails-3
like image 191
bowsersenior Avatar answered May 21 '26 15:05

bowsersenior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!