Git Product home page Git Product logo

ratyrate's Introduction

RatyRate Stars Rating Gem

A Ruby Gem that wrap the functionality of jQuery Raty library, and provides optional IMDB style rating.

Gem Version Build Status Dependency Status Code Climate License Support jQuery Raty Stories in Ready Code Triagers Badge Backers on Open Collective Sponsors on Open Collective

Repository

This is a fork against the repository muratguzel/letsrate, the aim of this fork is to refresh the development in this Gem with a new scope and features, so please if you have any pull request issue it here, also I imported all the issues in the original repo.

Changelog from the main repository

  1. Exposed a lot of jQuery Raty plugin features
  2. Added cancel button that can be customized and inserted to left or right
  3. Added the ability to set custom star images for on, half or off state
  4. Added the ability to set a custom path for the images
  5. Added the ability to enable/disable half stars
  6. Added the ability to turn on/off half star
  7. Their is a new option now to disable or enable the rating after the first rate
  8. Added a star style to show just the score of the dimension, but this star is not editable
  9. Added an overall average star just like IMDB style
  10. Created a Heroku app to illustrate this Gem's purpose and features (MovieStore)
  11. Wrote a complete tutorial on SitePoint that illustrates how to use this gem
  12. Nothing else
  13. :wq

TODO

  1. Write RSpec tests for this Gem
  2. Add option to show the number of users who gave rates
  3. Add a share helper to Facebook, Twitter
  4. Force refresh after rating when disable_after_rate and imdb_avg options is set to true.

Detailed view of the new features

Detailed view of the new featurews

Complete tutorial for this Gem on SitePoint - Ruby

I wrote a complete tutorial on SitePoint to cover this Gem's features in detail, if you are concerned to learn more about it just pay a visit to this link.

Instructions

Install

Add the ratyrate gem into your Gemfile

gem 'ratyrate'

Generate

rails g ratyrate user

The generator takes one argument which is the name of your existing devise user model UserModelName. This is necessary to bind the user and rating datas. Also the generator copies necessary files (jQuery Raty plugin files, star icons and JavaScript files)

Example:

Suppose you will have a devise user model which name is User. The devise generator and ratyrate generator should be like below

rails g devise:install
rails g devise user

rails g ratyrate user # => user is the model generated by devise

This generator will create Rate and RatingCache models, db/migrations, and link to your user model.

Database Migration

Run the migrations:

rake db:migrate

Javascript include

//= require jquery.raty
//= require ratyrate

Prepare

I suppose you have a car model

rails g model car name:string

You should add the ratyrate_rateable function with its dimensions option. You can add multiple dimensions.

class Car < ActiveRecord::Base
  ratyrate_rateable "speed", "engine", "price"
end

Then you need to add a call ratyrate_rater in the user model.

class User < ActiveRecord::Base
  ratyrate_rater
end

Using

There is a helper method which name is rating_for to add the star links. By default rating_for will display the average rating and accept the new rating value from authenticated user.

<%# show.html.erb -> /cars/1 %>

Speed  : <%= rating_for @car, 'speed' %>
Engine : <%= rating_for @car, 'engine' %>
Price  : <%= rating_for @car, 'price' %>

Available Options

1- If you need to change the star number, you should use star option like below.

Speed  : <%= rating_for @car, 'speed', star: 10 %>
Engine : <%= rating_for @car, 'engine', star: 7 %>
Price  : <%= rating_for @car, 'price' %>

2- If you want to disable/enable the rating after user's first rate use the new option disable_after_rate

Speed : <%= rating_for @car, 'speed', disable_after_rate: true %>

To enable changes after first user rate set disable_after_rate to false

3- To enable half stars use the option enable_half

Speed : <%= rating_for @car, 'speed', enable_half: true %>

4- To show or hide the half stars use half_show

Speed : <%= rating_for @car, 'speed', half_show: true %>

5- To change the path in which the star images (star-on.png, star-off.png, star-half.png, ..etc) are located use

Speed : <%= rating_for @car, 'speed', star_path: true %>

To just change one of the star images choose from these options (star_on, star_off, star_half)

6- To add the cancel button to the left, or right of the stars use (default is false)

Speed : <%= rating_for @car, 'speed', cancel: true %>

7- To change the place of the cancel button (left, or right) use (default is left)

Speed : <%= rating_for @car, 'speed', cancel_place: left %>

8- To change the hint on the cancel button use (default is "Cancel current rating!" )

Speed : <%= rating_for @car, 'speed', cancel_hint: 'Cancel this rating!' %>

9- To change the image of the cancel on button use

Speed : <%= rating_for @car, 'speed', cancel_on: 'cancel-on2.png' %>

10- To change the image of the cancel off use

  Speed : <%= rating_for @car, 'speed', cancel_off: 'cancel-off2.png' %>

Other Helpers

You can use the rating_for_user helper method to show the star rating for the user.

Speed : <%= rating_for_user @car, current_user, 'speed', star: 10 %>

And you can use the imdb_style_rating_for to show a similar to IMDB rating style.

Speed : <%= imdb_style_rating_for @car, current_user %>

Semantic Versioning

Ratyrate attempts to follow semantic versioning in the format of x.y.z, where:

x stands for a major version (new features that are not backward-compatible).

y stands for a minor version (new features that are backward-compatible).

z stands for a patch (bug fixes).

In other words: Major.Minor.Patch.

Feedback

If you find bugs please open a ticket at https://github.com/wazery/ratyrate/issues

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

ratyrate's People

Contributors

alexanderad avatar aniliyidogan avatar bitdeli-chef avatar hechen0 avatar joeyates avatar jonatassalgado avatar jq-jay avatar klaustrainer avatar monkeywithacupcake avatar muratguzel avatar murrekatt avatar nbirnel avatar onlinetocode avatar pablof7z avatar petehuang avatar sangnuce avatar skyeagle avatar sonalkr132 avatar styx avatar thekindofme avatar varunbatrait avatar veduket avatar waffle-iron avatar wazery avatar yihyang avatar zewelor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ratyrate's Issues

New options

Issue by SanderMander
Sunday Jun 15, 2014 at 07:03 GMT
Originally opened as muratguzel#73


I've add new option to rating_for_user, rating_for which is :readonly option. This option show rating in readonly mode. Also i have add :can_change option to letsrate_rateable method, which is can allow users to change rating after rate. In previous version if user try to change rating then "User has already rated." exception will be raised. Also i have change associations methods call, because in rails 3 it throw exception "invalid arguments"


SanderMander included the following code: https://github.com/muratguzel/letsrate/pull/73/commits

No method 'raty'

Issue by gugguson
Saturday Jan 12, 2013 at 20:44 GMT
Originally opened as muratguzel#12


Hello.

I have followed your instructions and I get this error in the browser console and the star ratings aren't displayed:

Uncaught TypeError: Object [object Object] has no method 'raty' letsrate.js:5
(anonymous function) letsrate.js:5
fire jquery.js:975
self.fireWith jquery.js:1085
jQuery.extend.ready jquery.js:407
DOMContentLoaded

Updating :disable_after_rate and readonly option and associated bugs

In the Readme it said that, "Their is a new option now to disable or enable the rating after the first rate", but there was no follow up information in the readme on how to implement this.

I went through the rating_for helper, and found that I could set :disable_after_rate => false in my rating_for:

 <%= rating_for @product, "quality", :enable_half => true, :half_show => true, :disable_after_rate => false %>

This solved the problem and should be referenced in the readme, but it also created a new issue. Now unsigned in users can make ratings. Fortunately, the ratings do not save on the database, but it is still not good to make non-users make faux ratings.

Lastly, is there a way to create an additional read only in addition to the unrated one? It would be awesome to be able to list a current_user rating and an average rating on the same page!

Travis build failed

Issue by wazery
Sunday Jul 06, 2014 at 13:17 GMT
Originally opened as muratguzel#75


I see that there are a lot of PRs and everytime Travis build fails, can anyone fix this issue, so the PRs can be merged?

Conflicts with ActiveAdmin - undefined method klass for nil:NilClass around line#2 insert_tag renderer_for(:index)

I'm using activeAdmin for my admin dashboard and I have used ratyrate successfully on my views and it works like a charm. However, when I open up an admin page and try to visit a page that has its model linked to ratyrate, it throws this error.

Here is the trace

ActionView::Template::Error (undefined method klass' for nil:NilClass): 1: insert_tag renderer_for(:index) activerecord (4.1.1) lib/active_record/reflection.rb:505:insource_reflection'
activerecord (4.1.1) lib/active_record/reflection.rb:543:in chain' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/filters/resource_extension.rb:104:inblock in default_association_filters'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/filters/resource_extension.rb:104:in reject!' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/filters/resource_extension.rb:104:indefault_association_filters'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/filters/resource_extension.rb:95:in default_filters' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/filters/resource_extension.rb:81:infilter_lookup'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/filters/resource_extension.rb:22:in filters' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/filters/resource_extension.rb:127:inblock in filters_sidebar_section'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/helpers/optional_display.rb:25:in instance_exec' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/helpers/optional_display.rb:25:indisplay_on?'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/resource/sidebars.rb:17:in block in sidebar_sections_for' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/resource/sidebars.rb:17:inselect'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/resource/sidebars.rb:17:in sidebar_sections_for' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/views/pages/base.rb:101:insidebar_sections_for_action'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/views/pages/base.rb:125:in skip_sidebar?' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/views/pages/base.rb:63:inbuild_page_content'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/views/pages/base.rb:47:in block (2 levels) in build_page' arbre (1.0.2) lib/arbre/element/builder_methods.rb:31:inblock in build_tag'
arbre (1.0.2) lib/arbre/context.rb:92:in with_current_arbre_element' arbre (1.0.2) lib/arbre/element/builder_methods.rb:49:inwith_current_arbre_element'
arbre (1.0.2) lib/arbre/element/builder_methods.rb:26:in build_tag' arbre (1.0.2) lib/arbre/element/builder_methods.rb:39:ininsert_tag'
arbre (1.0.2) lib/arbre/element/builder_methods.rb:18:in div' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/views/pages/base.rb:44:inblock in build_page'
arbre (1.0.2) lib/arbre/context.rb:92:in with_current_arbre_element' arbre (1.0.2) lib/arbre/element/builder_methods.rb:49:inwith_current_arbre_element'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/views/pages/base.rb:43:in build_page' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/views/pages/base.rb:10:inbuild'
arbre (1.0.2) lib/arbre/element/builder_methods.rb:30:in block in build_tag' arbre (1.0.2) lib/arbre/context.rb:92:inwith_current_arbre_element'
arbre (1.0.2) lib/arbre/element/builder_methods.rb:26:in build_tag' arbre (1.0.2) lib/arbre/element/builder_methods.rb:39:ininsert_tag'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/app/views/active_admin/resource/index.html.arb:2:in block in __home_rankit__bundler_ruby_______active_admin_____dee_bd___app_views_active_admin_resource_index_html_arb__980872317506965145_70094679355120' arbre (1.0.2) lib/arbre/context.rb:45:ininstance_eval'
arbre (1.0.2) lib/arbre/context.rb:45:in initialize' /home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/app/views/active_admin/resource/index.html.arb:1:innew'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/app/views/active_admin/resource/index.html.arb:1:in __home_rankit__bundler_ruby_______active_admin_____dee_bd___app_views_active_admin_resource_index_html_arb__980872317506965145_70094679355120' actionview (4.1.1) lib/action_view/template.rb:145:inblock in render'
activesupport (4.1.1) lib/active_support/notifications.rb:161:in instrument' actionview (4.1.1) lib/action_view/template.rb:339:ininstrument'
actionview (4.1.1) lib/action_view/template.rb:143:in render' actionview (4.1.1) lib/action_view/renderer/template_renderer.rb:55:inblock (2 levels) in render_template'
actionview (4.1.1) lib/action_view/renderer/abstract_renderer.rb:38:in block in instrument' activesupport (4.1.1) lib/active_support/notifications.rb:159:inblock in instrument'
activesupport (4.1.1) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.1.1) lib/active_support/notifications.rb:159:ininstrument'
actionview (4.1.1) lib/action_view/renderer/abstract_renderer.rb:38:in instrument' actionview (4.1.1) lib/action_view/renderer/template_renderer.rb:54:inblock in render_template'
actionview (4.1.1) lib/action_view/renderer/template_renderer.rb:62:in render_with_layout' actionview (4.1.1) lib/action_view/renderer/template_renderer.rb:53:inrender_template'
actionview (4.1.1) lib/action_view/renderer/template_renderer.rb:17:in render' actionview (4.1.1) lib/action_view/renderer/renderer.rb:42:inrender_template'
actionview (4.1.1) lib/action_view/renderer/renderer.rb:23:in render' actionview (4.1.1) lib/action_view/rendering.rb:99:in_render_template'
actionpack (4.1.1) lib/action_controller/metal/streaming.rb:217:in _render_template' actionview (4.1.1) lib/action_view/rendering.rb:82:inrender_to_body'
actionpack (4.1.1) lib/action_controller/metal/rendering.rb:32:in render_to_body' actionpack (4.1.1) lib/action_controller/metal/renderers.rb:32:inrender_to_body'
actionpack (4.1.1) lib/abstract_controller/rendering.rb:25:in render' actionpack (4.1.1) lib/action_controller/metal/rendering.rb:16:inrender'
actionpack (4.1.1) lib/action_controller/metal/instrumentation.rb:41:in block (2 levels) in render' activesupport (4.1.1) lib/active_support/core_ext/benchmark.rb:12:inblock in ms'
/usr/lib/ruby/1.9.1/benchmark.rb:295:in realtime' activesupport (4.1.1) lib/active_support/core_ext/benchmark.rb:12:inms'
actionpack (4.1.1) lib/action_controller/metal/instrumentation.rb:41:in block in render' actionpack (4.1.1) lib/action_controller/metal/instrumentation.rb:84:incleanup_view_runtime'
activerecord (4.1.1) lib/active_record/railties/controller_runtime.rb:25:in cleanup_view_runtime' actionpack (4.1.1) lib/action_controller/metal/instrumentation.rb:40:inrender'
actionpack (4.1.1) lib/action_controller/metal/implicit_render.rb:10:in default_render' actionpack (4.1.1) lib/action_controller/metal/responder.rb:238:indefault_render'
actionpack (4.1.1) lib/action_controller/metal/responder.rb:165:in to_html' responders (1.0.0) lib/responders/flash_responder.rb:104:into_html'
actionpack (4.1.1) lib/action_controller/metal/responder.rb:158:in respond' actionpack (4.1.1) lib/action_controller/metal/responder.rb:151:incall'
actionpack (4.1.1) lib/action_controller/metal/mime_responds.rb:400:in respond_with' inherited_resources (1.4.1) lib/inherited_resources/actions.rb:7:inindex'
/home/rankit/.bundler/ruby/1.9.1/active_admin-8299dee5bd08/lib/active_admin/resource_controller/streaming.rb:12:in index' actionpack (4.1.1) lib/action_controller/metal/implicit_render.rb:4:insend_action'
actionpack (4.1.1) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.1) lib/action_controller/metal/rendering.rb..

Im not sure why this happens ? but when I remove this line ratyrate_rateable "rating" from my model and visit the admin page for the same, it just works. I have followed the guidelines mentioned in the README and I do not know how to resolve this. Can you help on this please :)

letsrate only compatible with rails 4?

Issue by shaimo
Sunday Mar 23, 2014 at 14:23 GMT
Originally opened as muratguzel#65


Seems like rails 3 doesn't like the "-> { where dimension: nil}" syntax in letsrate_rateable.
I wish there were some brunch supporting previous versions of rails...

it can not work after adding readOnly option

Issue by sharp
Saturday Sep 14, 2013 at 02:24 GMT
Originally opened as muratguzel#41


In letsrate.js.erb:

$(function(){ 
    $(".star").raty({                  
        score: function(){
            return $(this).attr('data-rating')              
        }, 
        number: function() {
            return $(this).attr('data-star-count')
        },
        readOnly: function() {
            //console.log('sss')
            return false;//$(this).attr('data-readonly') == 'true'      
        },
        click: function(score, evt) {
            $.post('<%= Rails.application.class.routes.url_helpers.rate_path %>', 
                {
                    score: score, 
                    dimension: $(this).attr('data-dimension'),  
                    id: $(this).attr('data-id'),
                    klass: $(this).attr('data-classname')
                }, 
                function(data) {
                    if(data) {
                        // success code goes here ... 
                    }
            });
        }                        
    });           
});

If I add readOnly option , no matter it is true or false, the star can not be clicked.

Problems adding 'ratyrate' to my project

Hi, I'm newbie on RoR and I'm having a problem adding the Gem into my Gemfile.

As you said at the Readme, I have added the line "gem 'ratyrate'", but when I execute 'bundle install' I have this error message:

bin/bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...

Could not find gem 'ratyrate (>= 0) ruby' in the gems available on this machine.

And I don't know how to fix this problem... Can you tell me what I'm doing bad?

Rails -v -> 4.1.0
Ruby -v -> ruby 2.1.0p0 (2013-12-25 revision 44422)

Thanks for all...

undefined method 'average'

One question
How do I display stars on the index page?
It get an undefined method `average' for nil:NilClass when i try to put : Quality : <%= rating_for @post, "quality", :enable_half => true %>

It's OK on the show page.

Separate selected from available stars

Issue by michaelimstepf
Wednesday Mar 12, 2014 at 06:02 GMT
Originally opened as muratguzel#63


Scenario:

  • Using the rating_for_user method
  • User has previously rated an object and reloaded the page

Problem:
The number of available stars now matches the previous rating (as opposed to the number of stars in the option hash specified or the default value of 5). For example if the previous rating was 3, there are only 3 out of 5 stars shown and the rating can't be changed to anything above 3 stars.


michaelimstepf included the following code: https://github.com/muratguzel/letsrate/pull/63/commits

Rake rollback and redo broken

Issue by joelmaranhao
Thursday Feb 07, 2013 at 16:08 GMT
Originally opened as muratguzel#14


Since I installed letsrate, my rake db:migrate:redo or rake db:rollback will only redo or rollback the migration for letsrate.

I am obviously losing all the rating data after any attempt of redo or rollback of the last migration on my database.

I detailed the problem on stackoverflow, http://stackoverflow.com/questions/14711908/rake-dbrollback-reverting-the-wrong-migration

My feelings is the install of the gem broke something in my setup, and I don't know how to fix it.

Any suggestion is most welcome.

Cheers,

joel

Could not Bundle Install

I am getting:
"Could not find gem 'ratyrate (>= 0) ruby' in the gems available on this machine."
When trying to bundle install

RailsAdmin & letsrate Error (Rails4)

Issue by initabas
Monday Jul 15, 2013 at 16:16 GMT
Originally opened as muratguzel#38


After installation of letsrate
when I'm trying to edit any of my model in RailsAdmin I get

ActiveRecord::Reflection::ThroughReflection#foreign_key delegated to source_reflection.foreign_key, but source_reflection is nil

but in general letsrate works!

Certain options/symbols not working

While certain options/symbols such as :star work, certain options are not functioning for me such as :enable_half (false doesn't work for me), and :can_change (true doesn't work for me).

Also, when I return to a page I need to refresh the browser for the ratings to appear.

Lets Rate gem with field_for

Issue by railsfactory-bharani
Thursday May 29, 2014 at 16:23 GMT
Originally opened as muratguzel#71


I am new to letsrate gem and also saw existing bugs. No one post the issue like this. In order to avoid ajax call, I am customized letsrate.js.erb for form submission. Setting the values of letsrate scores, dimensions and klass in hidden fields. Till now everything works fine for me.

In Review model:
letsrate_rateable "speed"

In letsrate.js.erb:
click: function(score, evt) {
var _this = this;
$("#business_rate_score").attr("value", score);
$("#business_rate_dimension").attr("value", $(this).attr('data-dimension'));
$("#business_rate_klass").attr("value", $(this).attr('data-classname'));
}
When am trying to use field_for and use those hidden fields like this:
<%= f.fields_for :rates do |g| %>
input type='hidden' id="business_rate_score" name="score"
input type='hidden' id="business_rate_dimension" name="dimension"
input type='hidden' id="business_rate_klass" name="klass"
<% end %>

For making nested_attributes in Review model:
letsrate_rateable "speed"
accepts_nested_attributes_for :rates, :allow_destroy => true

It throws No association found for name `rates'. Has it been defined yet? (ArgumentError)

Is letsrate gem accepting nested attributes? Can you explain me to make nested attributes to save the values?

`has_many': wrong number of arguments (3 for 2) (ArgumentError)

Issue by shivakumaarmgs
Tuesday Mar 04, 2014 at 19:26 GMT
Originally opened as muratguzel#62


I followed the README and tried implementing this gem. Created all the necessary models, ran the generators and migrated the databases. Added necessary lines in User model and Conference model.

letsrate generator for User model. Here user model is devise generated model

rails g letsrate User

create  app/assets/javascripts/jquery.raty.js
      create  app/assets/images/star-on.png
      create  app/assets/images/star-off.png
      create  app/assets/images/star-half.png
      create  app/assets/javascripts/letsrate.js.erb
      create  app/controllers/rater_controller.rb
      create  app/models/rate.rb
      create  app/models/rating_cache.rb
       route  post '/rate' => 'rater#create', :as => 'rate'
      create  db/migrate/20140304180848_create_rating_caches.rb
      create  db/migrate/20140304180849_create_rates.rb

$ rake db:migrate
==  CreateRatingCaches: migrating =============================================
-- create_table(:rating_caches)
   -> 0.0015s
-- add_index(:rating_caches, [:cacheable_id, :cacheable_type])
   -> 0.0007s
==  CreateRatingCaches: migrated (0.0025s) ====================================

==  CreateRates: migrating ====================================================
-- create_table(:rates)
   -> 0.0026s
-- add_index(:rates, :rater_id)
   -> 0.0012s
-- add_index(:rates, [:rateable_id, :rateable_type])
   -> 0.0012s
==  CreateRates: migrated (0.0054s) ===========================================


#app/model/user.rb
class User < ActiveRecord::Base
  include PublicActivity::Common
  recommends :conferences
  letsrate_rater
.
.
end

#app/model/conference.rb
class Conference < ActiveRecord::Base
  searchkick autocomplete: ['subject']
  include PublicActivity::Common
  letsrate_rateable "quality"
.
.
end

So have prepared my app as per the instructions given in the README.
now when I run the rails server I get the following error.

/home/shivakumaarmgs/.rvm/gems/ruby-1.9.3-p484/gems/activerecord-3.2.9/lib/active_record/associations.rb:1197:in `has_many': wrong number of arguments (3 for 2) (ArgumentError)
    from /home/shivakumaarmgs/.rvm/gems/ruby-1.9.3-p484/gems/letsrate-1.0.9/lib/letsrate/model.rb:87:in `letsrate_rateable'
    from /home/shivakumaarmgs/Rails/talkingslate/app/models/conference.rb:5:in `<class:Conference>'
    from /home/shivakumaarmgs/Rails/talkingslate/app/models/conference.rb:1:in `<top (required)>'
    from /home/shivakumaarmgs/.rvm/gems/ruby-1.9.3-p484/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:469:in `load'
    from /home/shivakumaarmgs/.rvm/gems/ruby-1.9.3-p484/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:469:in `block in load_file'
and it goes on

What am I doing wrong

ruby version 1.9.3
rails version 3.2.9

How to eager load rating_caches?

Issue by tispratik
Thursday Dec 12, 2013 at 05:57 GMT
Originally opened as muratguzel#55


I have tried many different ways to eager load the rating caches for a users items. But can't seem to get it right. Can you please suggest?

RatingCache Load (0.3ms) SELECT "rating_caches".* FROM "rating_caches" WHERE "rating_caches"."cacheable_id" = $1 AND "rating_caches"."cacheable_type" = $2 AND "rating_caches"."dimension" IS NULL ORDER BY "rating_caches"."id" ASC LIMIT 1 [["cacheable_id", 89], ["cacheable_type", "Item"]]

(0.3ms) SELECT COUNT(*) FROM "rates" WHERE "rates"."rater_id" = $1 AND (("rates"."dimension" IS NULL AND "rates"."rateable_id" = 89 AND "rates"."rateable_type" = 'Item')) [["rater_id", 52]]

RatingCache Load (0.3ms) SELECT "rating_caches".* FROM "rating_caches" WHERE "rating_caches"."cacheable_id" = $1 AND "rating_caches"."cacheable_type" = $2 AND "rating_caches"."dimension" IS NULL ORDER BY "rating_caches"."id" ASC LIMIT 1 [["cacheable_id", 87], ["cacheable_type", "Item"]]

(0.4ms) SELECT COUNT(*) FROM "rates" WHERE "rates"."rater_id" = $1 AND (("rates"."dimension" IS NULL AND "rates"."rateable_id" = 87 AND "rates"."rateable_type" = 'Item')) [["rater_id", 52]]

letsrate -- the stars are not displayed :(

Issue by zhall
Saturday Jul 06, 2013 at 20:18 GMT
Originally opened as muratguzel#35


I am using rails 3.2.8 gem, ruby 1.9.3 and want to add star rating to my project. I am using the letsrate gem. The stars are not displayed. I know this is something to do either with .js or the .css files. There is no .css file though for this gem. The jquery.raty.js and letsrate.js.erb files are in app/assets/javascripts directory.The star images are in app/assets/images directory.In my /show.html.erb file I wrote:

     <% content_for :javascript_includes do %>
     <%= javascript_include_tag 'jquery.raty.js','letsrate.js.'%>
     <% end %>    
    <dd>Quality : <%= rating_for @book, "quality",:star => 5 %><br/>
   Value For Money : <%= rating_for @book, "value_for_money",:star => 5  %><br/>
   Price : <%= rating_for @book, "price", :star => 5 %></dd><br/>
Im my views/layout/application.html.erb file I wrote:
<html>
<head>
    <title><%=@page_title || '*** T&T ***'%></title>
    <%= javascript_include_tag 'application'%>
   <%= yield :javascript_includes %>            
   <%= stylesheet_link_tag 'style','application', media: "all"%>
    <%= csrf_meta_tags %>
When application runs, the stars are not displayed. Do I need to write .css file? I am really, really in dire need of your help!!! Thank you.

Show ratings stats

Issue by timeon
Friday Feb 22, 2013 at 17:32 GMT
Originally opened as muratguzel#18


Is there a way to show rating stats like what's on Amazon.come? For example.

5 stars: ********** ( 10)
4 stars: **** ( 4)
3 stars: * ( 1)
2 stars: ** ( 2)
1 stars: ** ( 2)

rating_for_user with disable_after_rate => true get `ratings_given' for 22:Fixnum error

Issue by arthurccube
Thursday Sep 26, 2013 at 17:07 GMT
Originally opened as muratguzel#45


my call
" rating_for_user ratable, user, r, :disable_after_rate => true"

gives the following errors, which disappear without the disable_after_rate

undefined method `ratings_given' for 22:Fixnum

Extracted source (around line #18):

15: %lable=t("activerecord.attributes.rating.#{r}")
16: .rating_wrapper
17: - if user.present?
18: = rating_for_user ratable, user, r, :disable_after_rate => true
19: - else
20: = rating_for ratable, r, :disable_after_rate => true
21:

Application Trace | Framework Trace | Full Trace

app/views/ratings/_ratable.haml:18:in block in _app_views_ratings__ratable_haml___940430013_100816650' app/views/ratings/_ratable.haml:13:ineach'
app/views/ratings/_ratable.haml:13:in _app_views_ratings__ratable_haml___940430013_100816650' app/views/students/opinions/_nav_bar.haml:19:in_app_views_students_opinions__nav_bar_haml___121796833_107698390'
app/views/students/opinions/show.html.haml:15:in _app_views_students_opinions_show_html_haml__499083187_105337980' app/controllers/students/opinions_controller.rb:16:inshow'

show the stars on index

Issue by ph3s
Monday Mar 11, 2013 at 18:05 GMT
Originally opened as muratguzel#21


Hi thank you for a great gem. A question please.
How do I display stars on the index page of model? It trows an error
undefined methodaverage' for nil:NilClass`

It's OK on the show page tho

Also a small bag during the installation it generates two migration files with the same name, rails is refusing to migrate, I had to manually rename one of the files

STI problems

Got problems with STI twice, because you using something like this in your code: object.class, but when I working with STI I need it to be: object.class.base_class.

First of all it breaks the Ratyrate::update_rate_average ( you will call this function from obj.rate in RaterController ).

In this line avg.cacheable_type = self.class.name, because rails don't use in polymorphic associations STI descendants, only base_class. So it will never find the RatingCache and will recreate it on every rate.

and second it breaks Ratyrate::can_rate?
in this line: user.ratings_given.where(dimension: dimension, rateable_id: id, rateable_type: self.class.name ).size.zero?

I am as Admin, can rate many times any Object, anybody except pure User also can do this.

NoMethodError caught when I'm trying destroy the rated object

Issue by monikaszalas
Monday Dec 03, 2012 at 13:57 GMT
Originally opened as muratguzel#10


I've decided using gem letsrate in my app, but I have some problem, probably caused by gem.

First some code:

I've got a model Article:

class Article < ActiveRecord::Base
  letsrate_rateable "quality"
  ...
end

and model User (generated by Devise):

class User < ActiveRecord::Base
  letsrate_rater
  ...
end

I've used generator according to readme instructions:

rails g letsrate user

Everything works great until I try destroy my article object, then I've got this error:

>> Article.last.destroy
Article Load (0.4ms)  SELECT `articles`.* FROM `articles` ORDER BY `articles`.`id` DESC LIMIT 1
   (0.1ms)  BEGIN
  Rate Load (0.4ms)  SELECT `rates`.* FROM `rates` WHERE `rates`.`rateable_id` = 1 AND `rates`.`rateable_type` = 'Article' AND `rates`.`dimension` IS NULL
  SQL (0.3ms)  DELETE FROM `rates` WHERE `rates`.`id` = 2
  RatingCache Load (1.2ms)  SELECT `rating_caches`.* FROM `rating_caches` WHERE `rating_caches`.`cacheable_id` = 1 AND `rating_caches`.`cacheable_type` = 'Article' AND `rating_caches`.`dimension` IS NULL LIMIT 1
  SQL (1.0ms)  DELETE FROM `rating_caches` WHERE `rating_caches`.`id` = 2
  Rate Load (0.3ms)  SELECT `rates`.* FROM `rates` WHERE `rates`.`rateable_id` = 1 AND `rates`.`rateable_type` = 'Article' AND `rates`.`dimension` = 'quality'
  Rate Load (0.3ms)  SELECT `rates`.* FROM `rates` WHERE `rates`.`rateable_id` = 1 AND `rates`.`rateable_type` = 'Article' AND `rates`.`dimension` = 'quality'
   (0.5ms)  ROLLBACK
NoMethodError: undefined method `association_class' for nil:NilClass
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/associations.rb:159:in `association'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/associations/builder/has_one.rb:49:in `has_one_dependent_destroy_for_quality_average'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.6/lib/active_support/callbacks.rb:422:in `_run_destroy_callbacks'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/callbacks.rb:254:in `destroy'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:236:in `block in destroy'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:194:in `transaction'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:208:in `transaction'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.1.6/lib/active_record/transactions.rb:236:in `destroy'
  from (irb):1
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.6/lib/rails/commands/console.rb:45:in `start'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.6/lib/rails/commands/console.rb:8:in `start'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.6/lib/rails/commands.rb:40:in `<top (required)>'
  from /Users/xyz/projekty/dentist/script/rails:6:in `require'
  from /Users/xyz/projekty/dentist/script/rails:6:in `<top (required)>'
from -e:1:in `load'
  from -e:1:in `<main>'

The error occures no matter if I use quality dimension or not. I will be very grateful for your reply where the problem is.

PS. Im'using the newest version of gem (letsrate (1.0.7))

How to get average from all users

Issue by legos
Sunday Apr 07, 2013 at 20:44 GMT
Originally opened as muratguzel#26


How would I get the average rating from all users for each attribute and also the average overall rating from all attributes? Also, is it possible to show a numerical value instead of the stars?

Object remains votable via JQuery after vote is placed

Issue by rceee
Saturday Feb 09, 2013 at 01:03 GMT
Originally opened as muratguzel#16


Not sure if this is a Rails 3.2 asset pipeline issue or what, but after placing a vote (the POST action happens fine), the javascript to be able to vote is still live and active. I am able to continue clicking stars, and in the console the model displays the "user already voted" error logs.

Jquery should be disabling the voting ability after a vote is cast, right?

losing rating capability after ajax load

Issue by uorji3
Thursday Nov 15, 2012 at 05:50 GMT
Originally opened as muratguzel#8


Let me first start by saying "Great gem".

On my page, I use your star rating but the user can click on a link to update a div element using ajax.
After the ajax load, all of the javascript for the star rating breaks.

I've been using the jquery "on" event for other javascript functions that I have created but I don't know how to use to fix the star rating.

How can I reload letsrate.js.erb and jquery.raty.js after an ajax load?

Can we show average rating and current user rating separately?

I would like my model to have one field for current user's rating, and one field for showing average rating. How do I enable this? Currently, I can have disable_after_rate: false, which will show the current user rating and allows editing, or I can set disable_after_rate: true and show average. How do I show both side by side, i.e, can I do something like:

<% if current_user %>
    Rating: <%= rating_for @movie, "rating", disable_after_rate: false %>
  <% end %>  
  <br/>
  Overall Rating: <%= rating_for @movie, "rating", disabled: true, imdb_avg: true %> # always disabled

Little hint to tutorial

Hi! In our project we explicitly including files in application.js and so we don't use //= require_tree .

Because of that I lost couple hours and couple piece of my patience till I saw the stars :)

It would be nice to add some thing like this to tutorial: "Don't forget explicitly to require JS files in your application.js if you not using //require_tree . "

Thanks in advance!

[feature request] Allow users to change the rating

Issue by andreslucena
Saturday Oct 20, 2012 at 08:10 GMT
Originally opened as muratguzel#4


Normally the users should be allowed to change their rating, for instance they can click on the rating they don't actually want by mistake.

Right now, if the user do this, letsrate raises an exception saying "User has already rated.".

By the way, great gem! I think it's the only rating gem working in rails3 that works without any hack, just following the documentation :) Congrats!

create_migration method def changed to create_letsrate_migration to avoid collision with rails create_migration method name

Issue by dasibre
Wednesday May 14, 2014 at 00:18 GMT
Originally opened as muratguzel#69


create_migration method def changed to create_letsrate_migration to avoid collision with rails create_migration method name
/Users/jnaadjie/.rvm/gems/ruby-2.1.1@bleedingedge/gems/letsrate-1.0.9/lib/generators/letsrate/letsrate_generator.rb:37:in create_migration': wrong number of arguments (3 for 0) (ArgumentError) from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@global/gems/railties-4.1.0/lib/rails/generators/migration.rb:63:inmigration_template'
from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@bleedingedge/gems/letsrate-1.0.9/lib/generators/letsrate/letsrate_generator.rb:33:in create_cacheable_migration' from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/command.rb:27:inrun'
from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/invocation.rb:126:in invoke_command' from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/invocation.rb:133:inblock in invoke_all'
from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/invocation.rb:133:in each' from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/invocation.rb:133:inmap'
from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/invocation.rb:133:in invoke_all' from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/group.rb:232:indispatch'
from /Users/jnaadjie/.rvm/gems/ruby-2.1.1@global/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'


dasibre included the following code: https://github.com/muratguzel/letsrate/pull/69/commits

Stars not displayed in production (Heroku)

Hi...

I'm deploying my app on Heroku and I've a problem with star images.

The app in development it's working OK.

It seems that the problem in production resides in the way that the images are accessed.
You can't access to the image name directly because they're precomplied rake adds a hash between the name and the extension.

Any suggestion?

Thanks...

Migration from ajaxful_rating gem

Hi wazery,

With Rails 4.1 migration I can no longer use ajaxful_rating gem, so I decided to try your ratyrate gem. The integration goes well so far, but now I have to migrate the data from the previous database design to the new one. The rates table looks the same for both gems, so there are no issues here. However, ajaxful_rating gem was keeping average as a single column on the rated object while in your (or letsrate gem) implementation there are three more tables (rating_caches, average_caches, and overall_averages).

I guess eventually I will be able to prepare a migration that populates ajaxful_rating's single column into the three new tables correctly, but it will require some code digging etc. So, I was wondering whether you could add some explanations about the three tables. You could use your car rating example. In ajaxful_rating gem the rates table would be populated in the same way, and in addition only the rating_average column in the cars table will be updated with corresponding average. So, my question is whether you could clearly show how to populate that rating_average into rating_caches, average_caches, and overall_averages tables.

An example of such migration will simplify life not only for me but for many others that will have to decide which gem to choose in the future. Please help me with some explanations, and I will provide you with the final migration code.

Thanks a lot!

How to disable ratings?

Hi wazery,

I am unable to show ratings in read-only mode. On the picture below I just want to show the user ratings average without any ability to rate. I am doing something like this:

<%= rating_for @Property, nil, half_show: true %>

My question is how I can remove the Cancel button and make the stars not interactive?

ratings

Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.