Hi so im trying to display a star rating on the website so far i’ve got the ratings in a form of a number however i want to times that number and display the equall amount of stars using a loop or somehting alike i.e. if the rating is 4 then 4 star pictures get printed out, any ideas?
my code so far…
number_with_precision(product.no_of_stars, :precision => 1) // this line prints out the number ans works just fine
im trying to do something like this…
product.no_of_stars.times do |i|
image_tag(“/images/star.jpg”)
end
but it keeps saying “undefined method `times’ for #”
I think it’s because your
product.no_of_starsis returning a float, whereas only Integers (or perhaps Fixnums) can respond totimes; if you’re happy with ignoring any fractions, you could try:Or if you always want an integer, then perhaps change your DB to use an integer column?
Otherwise it might work better to use javascript for your star rating; a quick google will give you plenty of results.