Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails如何根据分数填充星星?_Ruby On Rails_Twitter Bootstrap - Fatal编程技术网

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到5

def显示星星(分数)
(1..5).地图do|i|
图标(我可能会检查我
def display_stars(score)
  (1..5).map do |i| 
    icon(i <= score ? 'star' : 'star-empty')   
  end.join.html_safe
end