Giter Club home page Giter Club logo

Comments (13)

clairity avatar clairity commented on July 2, 2024 2

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.

ryanto avatar ryanto commented on July 2, 2024

Open db/schema.rb and paste your the "create_tables 'votes'...." section.

from acts_as_votable.

thatfunkymunki avatar thatfunkymunki commented on July 2, 2024

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.

ryanto avatar ryanto commented on July 2, 2024

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.

thatfunkymunki avatar thatfunkymunki commented on July 2, 2024

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.

ryanto avatar ryanto commented on July 2, 2024

Whoops, sorry about that.

What version of ruby and what version of rails?

from acts_as_votable.

thatfunkymunki avatar thatfunkymunki commented on July 2, 2024

action@cerebral-depravity-120411:/cerebral-depravity(master_)$ rails version
Rails 4.1.0
action@cerebral-depravity-120411:
/cerebral-depravity(master_)$ ruby --version
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]

from acts_as_votable.

vietqhoang avatar vietqhoang commented on July 2, 2024

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.

thatfunkymunki avatar thatfunkymunki commented on July 2, 2024

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.

thatfunkymunki avatar thatfunkymunki commented on July 2, 2024

I guess I was doing something wrong because it is working now. Thanks for your support!!!

from acts_as_votable.

vietqhoang avatar vietqhoang commented on July 2, 2024

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.

YouckFou46 avatar YouckFou46 commented on July 2, 2024

The problem was in the migration, somehow. Try and rewrite it that might help

from acts_as_votable.

jDeppen avatar jDeppen commented on July 2, 2024

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)

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.