Skip to content

Instantly share code, notes, and snippets.

@richlow
Created February 15, 2023 05:24
Show Gist options
  • Select an option

  • Save richlow/f1ea7196567798d8c1753670aa6838b9 to your computer and use it in GitHub Desktop.

Select an option

Save richlow/f1ea7196567798d8c1753670aa6838b9 to your computer and use it in GitHub Desktop.

Revisions

  1. richlow created this gist Feb 15, 2023.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #################################
    # Pre-req: install font awesome (fonts)

    #################################
    #star_rating_helper.rb
    module StarRatingHelper
    def star_rating(rating)
    full_star = "fas fa-star"
    empty_star = "far fa-star"
    stars = []

    for i in 1..5
    if i <= rating
    stars << full_star
    else
    stars << empty_star
    end
    end

    stars.map do |star|
    content_tag(:i, "", class: star)
    end.join("\n").html_safe
    end
    end

    #################################
    You call this in the view file

    <%= star_rating(space.rank) %>