Sha256: 9c689f6517ae54809420ff44097deaad6073d433cf10ec959a7033ed9fffd438

Contents?: true

Size: 1.25 KB

Versions: 45

Compression:

Stored size: 1.25 KB

Contents

module RailsConnector
  #
  # This helper provides methods for use with ratings.
  module DefaultRatingsHelper
    # Determines whether the current user has rated a CMS object.
    def rated_by_current_user?(obj)
      session[:rated_objs] && session[:rated_objs][obj.id]
    end

    # Builds the HTML markup for the ratings section.
    def stars_for_rating(obj)
      stars = "".html_safe
      (Rating::MINIMUM..Rating::MAXIMUM).collect do |score|
        stars << content_tag(:li, link_a_star(score, obj))
      end
      stars
    end

    private

    def link_a_star(score, obj)
      css_classes = ["", "one-star", "two-stars", "three-stars", "four-stars", "five-stars"]
      descriptions = ["",
        t(:"rails_connector.helpers.ratings.bad"),
        t(:"rails_connector.helpers.ratings.mediocre"),
        t(:"rails_connector.helpers.ratings.average"),
        t(:"rails_connector.helpers.ratings.good"),
        t(:"rails_connector.helpers.ratings.very_good")
      ]
      html_options = {
        :title => "#{score} von #{Rating::MAXIMUM} Sternen",
        :class => css_classes[score],
        "data-description" => descriptions[score]
      }
      link_to(score.to_s, ratings_url(:action => :rate, :id => obj.id, :score => score), html_options)
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
infopark_rails_connector-6.9.1.3.22208381 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.9.0.3.197272233 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.3.174.51542603 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.3.115.227021242 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.3.73.75172665 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.3.2.153416031 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.3.67.110847540 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.3.1.23895778 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.2.36.82613853 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.2.7.128454143 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.1.26.236500544 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.1 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.0.539.93842523 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.0.529.114081979 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.0.518.30999728 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.0.515.34928522 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.0.498.46559598 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.0.480.261594408 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.0.444.171626367 app/helpers/rails_connector/default_ratings_helper.rb
infopark_rails_connector-6.8.0.406.131718077 app/helpers/rails_connector/default_ratings_helper.rb