Reputation: 926
I have a star ratings feature. And pretty much, I would like it to display a particular image depending on the number.
Here's some pseduo code I would like to do in my review.rb model
def show_stars
if rating = 1
display 1star.png
elsif rating = 2
display 2star.png
elsif rating = 3
display 3star.png
elsif rating = 4
display 4star.png
elsif rating = 5
display 5star.png
end
How would I make this code work? And also, how would I make it display right in a view file?
Upvotes: 0
Views: 618
Reputation: 5508
This should really go into a view helper.
def show_stars(review)
image_tag "#{review.rating}star.png"
end
Then in your view:
<%= show_stars @review %>
Upvotes: 4