Comments (13)
if anyone else runs into this issue of the cache seemingly not working, a restart of the rails server just might fix it. =)
from acts_as_votable.
Open db/schema.rb
and paste your the "create_tables 'votes'...." section.
from acts_as_votable.
create_table "votes", force: true do |t|
t.integer "votable_id"
t.string "votable_type"
t.integer "voter_id"
t.string "voter_type"
t.boolean "vote_flag"
t.string "vote_scope"
t.integer "vote_weight"
t.datetime "created_at"
t.datetime "updated_at"
end
from acts_as_votable.
You don't have any of the cache columns on your table. Please see this page: https://github.com/ryanto/acts_as_votable#caching
from acts_as_votable.
I have the cached columns under my other model as stated in the link given:
create_table "cards", force: true do |t|
t.text "text"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_score", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
t.integer "cached_weighted_score", default: 0
t.integer "cached_weighted_total", default: 0
end
from acts_as_votable.
Whoops, sorry about that.
What version of ruby and what version of rails?
from acts_as_votable.
action@cerebral-depravity-120411:/cerebral-depravity(master_)$ rails version/cerebral-depravity(master_)$ ruby --version
Rails 4.1.0
action@cerebral-depravity-120411:
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
from acts_as_votable.
What happens when you try the following?
@card.count_votes_up
and @card.count_votes_down
Looking at the votable.rb, it looks like @card.get_likes
and @card.get_dislikes
will always hit the Vote table. Whereas the above will hit the cache columns of the votable model.
This still doesn't explain why your caching is not updating though...
Did you run the following command force caching of existing votes for the votable model? I am assuming the model is Card.
Card.find_each(&:update_cached_votes)
Also you don't need to call .size on @card.cached_votes_up
and @card.cached_votes_down
, since the return is an integer.
from acts_as_votable.
Yep, I ran the
Card.find_each(&:update_cached_votes)
in the migration. Then @card.cached_votes_up still gives me 0. I can't see the column updating either.
from acts_as_votable.
I guess I was doing something wrong because it is working now. Thanks for your support!!!
from acts_as_votable.
Hi,
i have a similar problem, maybe someone can help.
Displaying the cached_weighted score in show, there is no problem.
BUT as soon as i try to order/reorder int wont work
i tried running this:
@movie_suggestions.order(:cached_weighted_score => :desc)
@movie_suggestions.order('cached_weighted_score DESC')
@movie_suggestions.reorder(:cached_weighted_score => :desc)
@movie_suggestions.reorder('cached_weighted_score DESC')
@movie_suggestions.reorder(:weighted_score => :desc)
@movie_suggestions.order(:weighted_score => :desc)
all of this doesnt work, although the value of a single suggestion is displayed correctly in view using this:
suggestion.weighted_score
any suggestions on why it wont work?
What error output are you getting? The information will help in figuring out the source of your issue.
I am going off the assumption your results are not being ordered correctly. Do you have a default scope set on your MovieSuggestion
model? Have you tried chaining to_sql
to any of your calls to see what the SQL output is like? It may reveal what the issue is.
from acts_as_votable.
The problem was in the migration, somehow. Try and rewrite it that might help
from acts_as_votable.
The issue for me was that I was only utilizing vote_weight
as star rating, so I left vote_flag: nil
. I needed to set vote_flag
in order for the cache to update these:
cached_weighted_average # vote_flag must be true for the vote to count
cached_votes_total # vote_flag can't be nil or the vote won't count
note: cached_weighted_total
worked fine with vote_flag: nil
(these are the only three cache columns I'm using, so I can't speak to the others)
from acts_as_votable.
Related Issues (20)
- Using with UUID's as primary key HOT 1
- N+1 problem with my voters votes. HOT 7
- acts_as_votable issue HOT 5
- CHANGELOG HOT 2
- current_user.voted_for? @post returns false regardless of vote HOT 1
- acts_as_votable_options somehow became nil HOT 5
- How do I get vote weight for a previous vote HOT 1
- Migration Generator on Rails 6 HOT 9
- 0.12.0 => 0.12.1 version upgrade is a bit painful HOT 3
- Destroying voter does not update cached values in votable HOT 2
- undefined local variable or method `acts_as_votable' HOT 4
- Deprecation warning when returning within an ActiveRecord transaction in Rails 6.1
- Update CI matrix HOT 3
- acts_as_votable not compatible with Rails 6.1? HOT 1
- Add news attributes model Vote HOT 1
- Multiple different reactions? HOT 3
- cached_votes_total doesn't update during factory bot tests
- Conflict with active_admin_role gem
- Could not find table "votes"
- How to override the act_as_votable gem table votes in my applicatio
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acts_as_votable.