Comments (9)
What version of the Gem are you using?
from acts_as_votable.
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.
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.
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.
How did you end up fixing this?
from acts_as_votable.
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.
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.
I mean: gem 'acts_as_votable', '~> 0.10.0'
from acts_as_votable.
Cool, I shall update it, appreciated @ryanto, hope that didnt cost trouble for you :D
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.