Code Monkey home page Code Monkey logo

Comments (5)

schneems avatar schneems commented on June 26, 2024

This is an odd one. If you're saying it works sometimes, for some posts, but not other posts. Is there any pattern with the posts that cannot be liked? Perhaps certain id's that cannot be liked?

I would recommend tailing the log to make sure that the initial post works to the controller

heroku logs --tail

For some additional insight you can take a look at the result of target = Likeable.find_by_resource_id(params[:resource_name], params[:resource_id])

by calling puts target.inspect on the element to ensure it is being properly recovered from the database.

if that works every time, you can ensure the proper keys are being generated

puts target.like_key.inspect
puts current_user.like_key

If those look correct it is possible that your connection to redis is intermittent. You can try writing to redis directly

redis = Likeable.redis
puts redis.inspect # make sure this matches your redis-to-go information
puts redis.hset(target.like_key, current_user.id, Time.now.to_f)
puts redis.hkeys(target.like_key)

Let me know what the result of each of those tests are, and I can help trouble-shoot more. What version of Rails are you on?

from likeable.

cvrsor avatar cvrsor commented on June 26, 2024

Hi Richard,

Many thanks for your reply and help. Indeed, it is a very strange error: here's what I found after inspecting the elements you suggest:

  1. The post reaches the controller, I can see the 'Processing by LikesController#create as HTML' in the terminal window
  2. puts target.inspect correctly recovers the 'Post' element from database, all fields are shown correctly in the terminal window (#<Post id: 60, ...)
  3. puts target.like_key.inspect correctly returns "Posts:like:60"
  4. puts current_user.like_key returns Users:like:1

So I guess everything works fine until here.
Also, running redis = Likeable.redis in rails console spits out correctly my RedisToGo connection string, and I can set the hash.

Really strange error..

Only pattern I've noticed is that the first attempt to like/unlike always succeeds and every subsequent attempt always fails..And if I restart the server and try the same record it succeeds, it seems that the redis connection works only for the fist POST and then its gone!

Just in case you spot any stupid mistakes:
config/initializers/likeable.rb```
Likeable.setup do |likeable|
uri = URI.parse(ENV["REDISTOGO_URL"])
likeable.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
end


Hey, many thanks for your help, really appreciated!

from likeable.

cvrsor avatar cvrsor commented on June 26, 2024

Don't know if it helps, I'm running Rails v.3.0.10. I really have no idea where to start for debugging..

from likeable.

cvrsor avatar cvrsor commented on June 26, 2024

Hi Richard,

I think my issue is the same as issue #11 opened by styx!

I had not spotted this before, my 'unsuccessful' posts were sending in the correct resource id, however the target returned by find_by_resource_id is always the first post that is made (from when server started).

Something funny could be going on in likeable / module_methods.rb and specifically in def find_one(klass, id)
Thanks!

from likeable.

schneems avatar schneems commented on June 26, 2024

Thanks again for reporting this, i updated notes in #11. Should be fixed with Gem Version 0.1.1

from likeable.

Related Issues (9)

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.