Giter Club home page Giter Club logo

Comments (9)

ryanto avatar ryanto commented on July 2, 2024

What version of the Gem are you using?

from acts_as_votable.

jamesy829 avatar jamesy829 commented on July 2, 2024

I'm using the latest version

acts_as_votable (0.9.0)

an example in console

[5] pry(main)> u = User.first
  User Load (2.1ms)  SELECT  "users".* FROM "users"   ORDER BY "users"."id" ASC LIMIT 1
=> #<User id: 2, email: "[email protected]", encrypted_password: "$2a$10$SYJb0OWsjvii0zDDWIhWCeL2ZUYn02swSM/XjBFAOWp...", reset_password_token: "e68ee93f51920b8652b831c9dd937cefd91918313842b31b25...", reset_password_sent_at: "2014-05-26 23:27:53", remember_created_at: nil, sign_in_count: 5, current_sign_in_at: "2014-05-29 22:04:38", last_sign_in_at: "2014-05-26 23:32:03", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", failed_attempts: 0, unlock_token: nil, locked_at: nil, created_at: "2014-05-25 15:37:21", updated_at: "2014-05-29 22:04:38", domicile: nil, username: "test">
[6] pry(main)> p = Post.first
  Post Load (1.0ms)  SELECT  "posts".* FROM "posts"   ORDER BY "posts"."id" ASC LIMIT 1
=> #<Article id: 13, title: "asfdsafd", body: "afdsasdf", character_id: 1, type: "Article", created_at: "2014-05-27 01:32:10", updated_at: "2014-05-27 01:32:10", comments_count: 4, author_id: 2>
[7] pry(main)> p.class.base_class
=> Post(id: integer, title: string, body: text, character_id: integer, type: string, created_at: datetime, updated_at: datetime, comments_count: integer, author_id: integer)
[8] pry(main)> p.class.base_class.name
=> "Post"
[9] pry(main)> u.likes p
   (0.8ms)  SELECT COUNT(*) FROM "votes"  WHERE "votes"."votable_id" = $1 AND "votes"."votable_type" = $2 AND "votes"."voter_id" = 2 AND "votes"."vote_scope" IS NULL AND "votes"."voter_type" = 'User'  [["votable_id", 13], ["votable_type", "Post"]]
   (0.2ms)  BEGIN
  SQL (1.0ms)  INSERT INTO "votes" ("created_at", "updated_at", "votable_id", "votable_type", "vote_flag", "vote_weight", "voter_id", "voter_type") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id"  [["created_at", "2014-06-05 21:11:15.994753"], ["updated_at", "2014-06-05 21:11:15.994753"], ["votable_id", 13], ["votable_type", "Post"], ["vote_flag", "t"], ["vote_weight", 1], ["voter_id", 2], ["voter_type", "User"]]
   (0.4ms)  COMMIT
=> true
[10] pry(main)> p
=> #<Article id: 13, title: "asfdsafd", body: "afdsasdf", character_id: 1, type: "Article", created_at: "2014-05-27 01:32:10", updated_at: "2014-05-27 01:32:10", comments_count: 4, author_id: 2>
[11] pry(main)> p.votes_for
  ActsAsVotable::Vote Load (0.5ms)  SELECT "votes".* FROM "votes"  WHERE "votes"."votable_id" = $1 AND "votes"."votable_type" = $2  [["votable_id", 13], ["votable_type", "Post"]]
=> [#<ActsAsVotable::Vote id: 7, votable_id: 13, votable_type: "Post", voter_id: 2, voter_type: "User", vote_flag: true, vote_scope: nil, vote_weight: 1, created_at: "2014-06-05 21:11:15", updated_at: "2014-06-05 21:11:15">]
[12] pry(main)> p.votes_for.size
=> 1
[13] pry(main)> u.voted_for? p
   (0.5ms)  SELECT COUNT(*) FROM "votes"  WHERE "votes"."voter_id" = $1 AND "votes"."voter_type" = $2 AND "votes"."votable_id" = 13 AND "votes"."votable_type" = 'Article' AND "votes"."vote_scope" IS NULL  [["voter_id", 2], ["voter_type", "User"]]
=> false

from acts_as_votable.

jamesy829 avatar jamesy829 commented on July 2, 2024
    def voted_on? votable, args={}
      votes = find_votes(:votable_id => votable.id, :votable_type => votable.class.base_class.name,
                         :vote_scope => args[:vote_scope])
      votes.size > 0
    end

Looking at the method, if I called u.voted_for? p it should be using the article object parent class, which should equal to the Post class...

I am just looking over the specs and I do not see a scenario that uses STI, possibly add that to test

from acts_as_votable.

jamesy829 avatar jamesy829 commented on July 2, 2024

Found the issue, when I install the gem with gem 'acts_as_votable', '~> 0.9.0' it would install the correct version but the all references to using votable.class.base_class.name would be votable.class.name

from acts_as_votable.

ryanto avatar ryanto commented on July 2, 2024

How did you end up fixing this?

from acts_as_votable.

jamesy829 avatar jamesy829 commented on July 2, 2024

I ended up configuring my Gemfile to point directly to github
gem 'acts_as_votable', github: "ryanto/acts_as_votable"
It seems if bundle install directly, its pulling the correct version but the codebase is behind

from acts_as_votable.

ryanto avatar ryanto commented on July 2, 2024

Ah sorry about that. Just pushed the most recent gem to rubygems:

You can use:

gem 'acts_as_votable', '~> 0.10.0'

from acts_as_votable.

ryanto avatar ryanto commented on July 2, 2024

I mean: gem 'acts_as_votable', '~> 0.10.0'

from acts_as_votable.

jamesy829 avatar jamesy829 commented on July 2, 2024

Cool, I shall update it, appreciated @ryanto, hope that didnt cost trouble for you :D

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.