L
L
lavezzi12015-09-13 12:13:13
Ruby on Rails
lavezzi1, 2015-09-13 12:13:13

How to pin a comment to the top of the list of all comments?

Hello. The comment has a boolean value, if it is true, then you need to pin it to the top of all comments. Like on a toaster. What to use? How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Dyachuk, 2015-09-13
@lavezzi1

@top_comments = @comments.where(top: true)

<div class='top comment'>
   <%= render @top_comment %>
</div>

T
thepry, 2015-09-13
@thepry

order(:my_boolean_field)
sort_by{ |comment| comment.top_comment? ? 0 : 1 }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question