Ruby on rails Rails如何根据分数填充星星?
目前,其刚填充的空开始:Ruby on rails Rails如何根据分数填充星星?,ruby-on-rails,twitter-bootstrap,Ruby On Rails,Twitter Bootstrap,目前,其刚填充的空开始: 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 但让我们假设我现在的分数是3,它应该显
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
但让我们假设我现在的分数是3,它应该显示以下内容:
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:我假设星星
的范围为0到5def显示星星(分数)
(1..5).地图do|i|
图标(我可能会检查我
def display_stars(score)
(1..5).map do |i|
icon(i <= score ? 'star' : 'star-empty')
end.join.html_safe
end