muratguzel / letsrate Goto Github PK
View Code? Open in Web Editor NEWThe best way to add rating capabilities to your rails application and your activerecord models.
Home Page: http://letsrate.herokuapp.com
The best way to add rating capabilities to your rails application and your activerecord models.
Home Page: http://letsrate.herokuapp.com
It would be great to be able to see how many users submitted a rating. How might you propose someone handle that?
/letsrate_generator.rb:37:in `create_migration': wrong number of arguments (3 for 0) (ArgumentError)
gem 'rails', '4.1.0'
I have installed devise with user model. I got this error in rails 4 and letsrate version 1.0.9 while applying this command
"rails g letsrate user".
Can you help me to solve this problem?
Using Rails 4.0.0 - Could this be causing an error relating to association names?
Hi!,
The function update_rate_average has a little issue in the calculation, average decrease while the quantity of votes increase.
Line 30 in letsrate/lib/letsrate/model.rb:
'a.avg = (a.avg + stars) / (a.qty+1)'
...should be:
'a.avg = (a.avg*a.qty + stars) / (a.qty+1)'
to take in account the number of votes that have the average in dividend... Maybe this calculation can be done in different way but with this it works.
Thanks!
The appropriate instruction to do so is
disable_after_rate = options[:disable_after_rate] || true
But as you can see (options[:disable_after_rate] || true) will still be true if you set options[:disable_after_rate] = false
I add this gem, make all from readme, but rate div not visible. May be javascript not included?
I added this gem to my rails application and got the error: "Undefined variable 'current_user'".
is there a way to fix this? I already did 'db:migrate' as well
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!
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 method
average' 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
It would nice if there was the option to show the user's previous rating instead of the average.
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)
Hello,
I find two other problem resolved like this:
1 on rate.rd model file, change attr_accessible by attr_accessor
2 on rater_controller.rb, just before last "end" class call, add :
private
def set_obj
@obj= (ligne 7 copie/paste eval line)
end
def obj_params
params.require(:rater).permit(:klass, :stars, :dimension, :score, :rate)
end
then, take off the ligne 7 (obj=eval.....)
and add "before_action :set_obj, only: [:create]" just after class declaration
(this was for strong_parameter process for rails-4)
3 on gem file of letsrate (model.rb)
change:
line 9:
r.rater_id = user_id.id (and not user_id)
line 45:
......and rater_id=#{user_id.id}...... (and note user_id)
this will work good and not make error 500 server for mysql. Also, no more warning for strong_parameter in rails-4
I try to find a way for call "klass" controller without "eval" ruby function...
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?
I am using the letsrate gem in Rails 4 application. I have added the gem into my lib file and changed it a bit for making it to work with Rails 4. Now I am getting a deprecated warning like this:
DEPRECATION WARNING: The following options in your Performer.has_many :rates_without_dimension declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:
has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'
should be rewritten as the following:
has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:76) DEPRECATION WARNING: The following options in your Performer.has_one :rate_average_without_dimension declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:
has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'
should be rewritten as the following:
has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:79) DEPRECATION WARNING: The following options in your Performer.has_many :performance_rates declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:
has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'
should be rewritten as the following:
has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from block in letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:84) DEPRECATION WARNING: The following options in your Performer.has_one :performance_average declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:
has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'
should be rewritten as the following:
has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from block in letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:91)
The part of the file which generates such an error is this:
module ClassMethods
def letsrate_rater
has_many :ratings_given, :class_name => "Rate", :foreign_key => :rater_id
end
def letsrate_rateable(*dimensions)
has_many :rates_without_dimension, :as => :rateable, :class_name => "Rate", :dependent => :destroy, :conditions => {:dimension => nil}
has_many :raters_without_dimension, :through => :rates_without_dimension, :source => :rater
has_one :rate_average_without_dimension, :as => :cacheable, :class_name => "RatingCache",
:dependent => :destroy, :conditions => {:dimension => nil}
dimensions.each do |dimension|
has_many :"#{dimension}_rates", :dependent => :destroy,
:conditions => {:dimension => dimension.to_s},
:class_name => "Rate",
:as => :rateable
has_many :"#{dimension}_raters", :through => "#{dimension}_rates", :source => :rater
has_one :"#{dimension}_average", :as => :cacheable, :class_name => "RatingCache",
:dependent => :destroy, :conditions => {:dimension => dimension.to_s}
end
end
I have tried bringing the :dependent=>:destroy to the last part of the line and changing conditions => {:dimension => dimension.to_s} to -> {:dimension => dimension.to_s}. It only throws errors. What am I doing wrong?
using rails 4.0.0 and ruby 2.0, when i try create rate, gem is not creating rates, may be trouble with strong parameters?
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?
a command rake assets: precompile raises the following
undefined method `rate_path' for #Module:0x9d31338
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
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...
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))
Is the demo app source available?
I have two models:
class Resource
end
class Tutorial < Resource
letsrate_rateable "name"
end
When I rate a Tutorial
, RatingCache
saves the correct type (Tutorial
):
=> #<RatingCache id: 41, cacheable_id: 9, cacheable_type: "Tutorial", avg: 3.0, qty: 1, dimension: "name", created_at: "2014-03-12 05:06:09", updated_at: "2014-03-12 05:06:09">
However, when I call the average
method in the Letsrate
module, it searches for RatingCaches
of the parent class (Resource
), not the child class (Tutorial
). In other words, when I call self.send("#{dimension}_average")
, I get this SQL:
RatingCache Load (0.2ms) SELECT "rating_caches".* FROM "rating_caches" WHERE "rating_caches"."cacheable_id" = $1 AND "rating_caches"."cacheable_type" = $2 AND "rating_caches"."dimension" = 'name' ORDER BY "rating_caches"."id" ASC LIMIT 1 [["cacheable_id", 9], ["cacheable_type", "Resource"]] => nil
What needs to be changed so when saving and retrieving RatingCaches
, the cacheable_type
matches (either Tutorial
or Resource
)?
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?
$ rake assets:precompile RAILS_ENV=production
c:/Ruby193/bin/ruby.exe c:/Ruby193/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=ass
rake aborted!
undefined method `rate_path' for #Module:0x39accc8
(in C:/MYAPP/app/assets/javascripts/letsrate.js.erb)
which is this line =>
$.post('<%= Rails.application.class.routes.url_helpers.rate_path %>',
Rails 3.2.6
Ruby 1.9.3
Windows 7
letsrate 1.0.7
You can check my repository:
I guess I need to make helper . but how make that all thee displayed in one rate I need to display in "view" overall rating of three parametres "quality", "Service", "Price" any ideas?
its useful thing...
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);
}
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?
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!
It currently allows a user to rate multiple times. Is there a way to limit it to one?
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.
I use the rate_for_user for dimension like below
" rating_for_user ratable, user, r"
it works if user already given rates to the dimension.
But it just display an zero length bar for dimension i haven't rated.
Thanks!
Is there a way to display the rating(s) a user submitted?
For example, the rating_for helper only displays the average rating from a collection of users but I would like to be able to display the individual ratings that the user submitted as well (not the averages).
POST http://localhost:3000/rate 500 (Internal Server Error) jquery.js:8417
send jquery.js:8417
jQuery.extend.ajax jquery.js:7969
jQuery.(anonymous function) jquery.js:7496
$.raty.click letsrate.js:13
(anonymous function) jquery.raty.js:185
jQuery.event.dispatch jquery.js:3064
elemData.handle.eventHandle jquery.js:2682
Any idea if this is a routes issue? I didn't see a specific route needed in the readme. Should there be one?
Thanks,
Joe
follow the install as read on doc, but not work.
rails 4
with gems: devise, cancan
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 %>
nvm
Awesome gem, thanks for your hard work guys!
Rails 4 doesn't like routes that start with match
and don't have the HTTP method(s) specified. Maybe something you could change in the source code for future use. Is it only get or both get and post?
get '/rate' => 'rater#create', :as => 'rate'
OR
match '/rate', to: 'rater#create', :as => 'rate', via: [:get, :post]'
Thx
migu at Laptop in ~/Projects/zookal-digital on master
$ 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 match '/rate' => 'rater#create', :as => 'rate'
create db/migrate/20140102015045504_create_rating_caches.rb
create db/migrate/20140102015045505_create_rates.rb
migu at Laptop in ~/Projects/zookal-digital on master*
$ rake db:migrate
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
rake aborted!
You should not use the `match` method in your router without specifying an HTTP method.
If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.
If you want to expose your action to GET, use `get` in the router:
Instead of: match "controller#action"
Do: get "controller#action"
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:191:in `normalize_conditions!'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:67:in `initialize'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1443:in `new'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1443:in `add_route'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1422:in `decomposed_match'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1403:in `block in match'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1394:in `each'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/mapper.rb:1394:in `match'
/Users/migu/Projects/zookal-digital/config/routes.rb:2:in `block in <top (required)>'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `instance_exec'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:341:in `eval_block'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:319:in `draw'
/Users/migu/Projects/zookal-digital/config/routes.rb:1:in `<top (required)>'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `each'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `call'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/file_update_checker.rb:75:in `execute'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:27:in `updater'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/migu/Projects/zookal-digital/config/environment.rb:5:in `<top (required)>'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application.rb:189:in `require_environment!'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/gems/railties-4.0.2/lib/rails/application.rb:250:in `block in run_tasks_blocks'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/bin/ruby_executable_hooks:15:in `eval'
/Users/migu/.rvm/gems/ruby-2.0.0-p247@zookal-digital/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
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
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
Dears,
I was trying the gem letsrate
Now I am trying to remove it
using :
rake db:rollback
rails d letsrate user
but after that when I try to access the book show page
it says :
rate is defined by ActiveRecord
ActiveRecord::DangerousAttributeError in Books#show
any solution ?
It is refusing this following :
<%= review.rate %>
Thank you
update the non editable stars?
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:in
each'
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:in
show'
There is a issue with can_rate? method, It's sql query when dimension is nil was:
"select count(*) as cnt from rates where rateable_id=33 and rateable_type='ABC' and rater_id=2 and dimension=''
instead of
"select count(*) as cnt from rates where rateable_id=33 and rateable_type='ABC' and rater_id=2 and dimension is null"
Please have a look and take a appropriate action to resolve the issue.
Thanks in advance.
I'm using turbolinks with Rails 4.1 and the star ratings don't display the selected rating upon visiting a new page.
From your readme: obj = eval "#{params[:klass]}.find(#{params[:id]})"
- this screams "abuse me".
Is there a way to display rating_for star values in index view? Currently rating_for only works in show view.
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]]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.