NooBskie
NooBskie

Reputation: 3841

Converting integer to star rating

Firstly here is my file structure

application_helper.rb

module ApplicationHelper
  def show_stars(review)
    image_tag review.rating
  end
end

Controller: customers_controller.rb

class CustomersController < ApplicationController
  before_action :require_admin
  # reviews
  def reviews
    @reviews = Review.all
  end
end

view: reviews.haml

%table.table.table-striped
  %thead
    %tr
      %th{ :style => "width:8%" } Ratings
      %tbody
        - @reviews.each do |review|
          %tr
            %td{ :style => "text-align:center" }= review.rating.show_stars

I have rating setup as a integer in my schema and what I am trying to do is convert the integer into a star image via the application helper. However when i try using my method i end up getting

undefined method `show_stars' for 4:Fixnum // 4 is my rating value

What am I missing here? I'm just starting out on ruby so any advice is appreciated.

Upvotes: 0

Views: 508

Answers (1)

Alexander Kireyev
Alexander Kireyev

Reputation: 10825

Your method accepts rating (signature show_stars(review)), so use it properly: change review.rating.show_stars to show_stars(review)

Upvotes: 2

Related Questions