Giter Club home page Giter Club logo

Comments (5)

ryanto avatar ryanto commented on July 20, 2024

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.

ewherrmann avatar ewherrmann commented on July 20, 2024

@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.

ewherrmann avatar ewherrmann commented on July 20, 2024

@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.

ryanto avatar ryanto commented on July 20, 2024

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.

ewherrmann avatar ewherrmann commented on July 20, 2024

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)

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.