Comments (5)
This is probably not something that will be added to acts_as_votable. You can of course change the vote class after_save if you need it for your project.
from acts_as_votable.
@ryanto Are you recommending adding the after_save callback to the generated Vote model or the ActsAsVotable::Vote model? I've added callbacks to the generated Vote model, but they don't seem to be getting called because the updates are actually through ActsAsVotable::Vote.
I could be wrong and I am still looking into it, but I believe that's what is happening.
from acts_as_votable.
@ryanto Sorry about the confusion on the last comment. I just looked through the gem and realized that there is no generated local model file. I inherited this code base and the previous developer must have created a Vote.rb file to add some custom methods.
If you look at the acts_as_follower gem, you will notice that they do generate a model file and then just reference that throughout the core methods. This allows for full customization of the model, including callbacks, without having to fork the original code.
https://github.com/tcocca/acts_as_follower
https://github.com/tcocca/acts_as_follower/tree/master/lib/generators/templates
from acts_as_votable.
Sorry, but we cannot add generated models to existing code bases.
You should probably not be adding after save callbacks to a vote model. There is probably a better way to solve what you are trying to accomplish. However, if it is a must then you can always reopen the vote model.
class ActsAsVotable::Vote
after_save :do_something
def do_something
# ...
end
end
from acts_as_votable.
Thanks for the suggestion and quick reply. I didn't even think about reopening the model and adding to it.
You are probably also right about a better way to solve the problem. Currently we have millions of records that could be votable and I need a way to quickly get all the votes for a votable owner. I didn't want to do an expensive join, so I was going to add a votable_owner_id and votable_owner_type to Vote and populate the new fields in the before_save callback.
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.