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

there seems to be an issue with parent_class_name #83

Closed
kdabalos opened this issue Oct 20, 2016 · 7 comments
Closed

there seems to be an issue with parent_class_name #83

kdabalos opened this issue Oct 20, 2016 · 7 comments

Comments

@kdabalos
Copy link

my classes look like the following

class User < ApplicationRecord
  include Clearance::User
  ...
  acts_as_follower
  ...
end
class Policy < ApplicationRecord
  include Searchable
  ...
  acts_as_followable
  ...
end
class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true
end

For some reason when I call this method user.follow(policy), the followable_type is not set to 'Policy' but to 'ApplicationRecord' which makes user.following?(policy) always return false. I looked at the parent_class_name method. the code below executes because the include? method returns false even if obj.class.superclass.name == 'ApplicationRecord'

unless parent_classes.include?(obj.class.superclass)
  return obj.class.superclass.name
end

I use Rails 5 and the master branch as indicated in another issue #79

@PelagicDev
Copy link

Did you ever figure this out @kdabalos? I'm using same Rails version and master branch too.

@BrahimDahmani
Copy link

i got the same issue, as i understood the code below is used for STI models, so if your class isn't STI model this function will return ApplicationRecord

unless parent_classes.include?(obj.class.superclass)
  return obj.class.superclass.name
end

i solved this by adding all non STI Model to initialiser like this
ActsAsFollower.custom_parent_classes = [ApplicationRecord, Report, Video, Survey, Message]

@BrahimDahmani
Copy link

actually this is mentioned in the doc, i didn't see that before now

@PelagicDev
Copy link

I did this as well, but I was seeing weird functionality. Sometimes it would create a record with :followable_type attribute set as 'User', and then the next record would be created with followable_type set as 'ApplicationRecord'.

I ended up forking this repo, and changed the code to only using 'User' as the followable_type. This isn't ideal since it isn't reusable for other model types, but I couldn't think of a better/quicker solution since I had beat my head on this for far too long.

@brchristian
Copy link
Contributor

@kdabalos This behavior should be fixed as of the merge of #56. Does that address this issue?

@PelagicDev
Copy link

Yeah, I think it does. This should be safe to close.

@brchristian
Copy link
Contributor

I’ll ping @jcoyne here with a heads up that this issue may be good to close, unless @kdabalos objects.

@jcoyne jcoyne closed this as completed Mar 23, 2017
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

5 participants