Scope ruby comments rated lower

1

I'm a neophyte in this Ruby, and for an application I'm doing, I need to define a method and a scope to show me the worst rated comments in ascending order: first worst and then improving.

I have written the inverse, thanks to some guidelines of an exercise, however I am not able to make the worst comments. So far I have this scope in my model comment.rb:

scope :rating_desc, -> { order(rating: :desc) }

This method in my model user.rb:

def highest_rating_comment
  comments.rating_desc.first
end

And in my show products view this:

<%= @product.highest_rating_comment %>

How should I do to get back the worst results? Thank you very much in advance

    
asked by Elena 21.02.2018 в 19:55
source

1 answer

0

You could define another scope for ascending order:

scope :rating_asc, -> { order(rating: :asc) }

and call it in another function

def worst_rating_comment
  comments.rating_asc.first
end
    
answered by 28.02.2018 / 19:24
source