Easy way to change a numerical to star rating for rails.

Chay Auker
2 min readJan 26, 2021

I created this application to assist customers in reviewing cafes so that others can make better use of their time in visiting cafes that best match their personality and expectations. I am also a Thai women that understand the value that a good cup of coffee can add to one’s day.

My program I created rates cafes base upon customer experiences. For this, a star rating scale is traditionally used instead of a numerical scale. Consumers are familiar with this format and intuitively comprehend ratings delivered in this way better. It is also more aesthetically pleasing to the eye and a 5-star rating is universally understood to be the standard of perfection.

There are a number of ways this can be accomplished. One easy way I discovered to do this was to use the following code in your html view page:

views/reviews/show.html.erb<%  @review.rating.to_i.times do  %>
<i class="bi bi-star-fill"></i>
<% end %></p> </div>

this line of code <i class=”bi bi-star-fill”></i> comes from bootstrap icon. You can change which icons you want or use css to style it.

This line of code <% review_rating.times do %> allows rating to be converted to integer and loops star icons that match the same number.

Then click the icon you want, copy the code, and paste it where the icon code is located.

This will display the above star rating base upon the number of stars that the user desires to rate the cafe.

Here is my walkthrough video.

If you would like to check out my code, here is my github.

--

--