Hullo,
I'm trying to make a website in ruby on rails and I'm building a helper to display a rating out of 5 as a series of stars. So far I have got:
def stars(score)
html = ""
if score >= 1
  image_tag "star.png", :alt => 'one'
else
  html << ""
end
if score >= 2
  html << (image_tag "star.png", :alt => 'one')
else
  html << ""
end
if score >= 3
  html << (image_tag "star.png", :alt => 'one')
else
  html << ""
end
if score >= 4
  html << (image_tag "star.png", :alt => 'one')
else
  html << ""
end
if score >= 5
  html << (image_tag "star.png", :alt => 'one')
else
  html << ""
end
end
but that does not seem a very good technique and it is writing out the html to the screen instead of showing an image.
Anyone have any ideas what I can do?
Thanks, Haziba
def stars(score)
  (image_tag("star.png", :alt => 'one') * score).html_safe
end
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论