Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem using current_user.following?(user) #84

Open
nelsonlho opened this issue Nov 10, 2016 · 7 comments
Open

Problem using current_user.following?(user) #84

nelsonlho opened this issue Nov 10, 2016 · 7 comments

Comments

@nelsonlho
Copy link

I am using acts_as_follower with Devise
So I notice something funny with current_user.following?(user)

current_user.following?(user) will always resolve to false, even when it's true, unless I restart my rails server

any thoughts?

@BrahimDahmani
Copy link

what's the result of current_user.follows ??

@fdahmadi
Copy link

fdahmadi commented Nov 17, 2016

I had same problem with some_model.all_following and some_model.follow(another_model)
Problem is for incompatibility with Rails 5

  • First use gem from github.
    in Gemfile:
    gem 'acts_as_follower', github: 'tcocca/acts_as_follower'
    and then
    bundle install
    It is in version 0.2.1 now
  • In Rails 5 models inherited from ApplicationRecord
    Find "follower_lib.rb" and change line 8
    if obj.class.superclass != ActiveRecord::Base
    To:
    if obj.class.superclass != ActiveRecord::Base || obj.class.superclass != ApplicationRecord
  • Then clean "follows" table.
  • Restart server

excuse me for my bad english. I can't explain better.
:)

@BrahimDahmani
Copy link

@fdahmadi this is an old solution, this is what the code look like right now

    DEFAULT_PARENTS = [ApplicationRecord, ActiveRecord::Base]

   # Retrieves the parent class name if using STI.
    def parent_class_name(obj)
      unless parent_classes.include?(obj.class.superclass)
        return obj.class.superclass.name
      end
      obj.class.name
    end

@nelsonlho so all what you have to do is listing your parent classes to in the initializer

ActsAsFollower.custom_parent_classes = [Book, Author, Publisher, User]

@fdahmadi
Copy link

fdahmadi commented Nov 20, 2016

My first approach is wrong. Sorry.

In my application users can follows each other
After some time server must be restarted because parent_class_name return ApplicationRecord instead of User and table is corrupted and application crash in user.all_following and user.follow(other_user) dos't work correctly
It seems bug is not in acts_as_follows but in somewhere in Puma. I don't know.
But i do the following approach and after 3 days it is working correctly

  • First use gem from github.
    in Gemfile:
    gem 'acts_as_follower', github: 'tcocca/acts_as_follower'
    and then
    bundle install
    It is in version 0.2.1 now
  • Find follower_lib.rb and comment 3 lines as follow
    def parent_class_name(obj)
      #unless parent_classes.include?(obj.class.superclass)
      #  return obj.class.superclass.name
      #end
      obj.class.name
    end
  • clean "follows" table.
  • Restart server

It works in my app. maybe it works on your app too.

excuse me for my bad english.
:)

@jeremylynch
Copy link

jeremylynch commented Dec 12, 2016

I also experienced this issue on Rails 5 and believe this is solved in PR #56

Use my fork if you like:

gem 'acts_as_follower', github: 'mrjlynch/acts_as_follower', branch: 'rails_5'

@merqlove
Copy link
Contributor

I think main problem within started Spring process & sometimes it's stuck.

@brchristian
Copy link
Contributor

@nelsonlho As @jeremylynch mentioned, I suspect that the merge of #56 should fix this. Does that take care of this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants