Reputation: 195
Currently its just populating empty starts:
def icon name
content_tag(:span, nil, class: "glyphicon glyphicon-#{name}")
end
def display_stars score
# here i need to somehow use icon('star')
(1..5).map { |i| icon('star-empty') }.join.html_safe
end
But let's say my score now 3, and it should display following:
Upvotes: 0
Views: 62
Reputation: 20815
def display_stars(score)
(1..5).map do |i|
icon(i <= score ? 'star' : 'star-empty')
end.join.html_safe
end
Upvotes: 1
Reputation: 5363
def display_stars score
full = (1..score).map { |i| icon('star') }
empty = (score..4).map { |i| icon('star-empty') }
(full+empty).join.html_safe
end
PS: I'm assuming that stars
range from 0 to 5
Upvotes: 1