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

use of dynamic finders defines respond_to? method #158

Closed
gitgary opened this issue Jun 7, 2013 · 4 comments · May be fixed by #587
Closed

use of dynamic finders defines respond_to? method #158

gitgary opened this issue Jun 7, 2013 · 4 comments · May be fixed by #587

Comments

@gitgary
Copy link

gitgary commented Jun 7, 2013

This problem has a simple solution -- keep 'config.use_dynamic_shortcuts' commented out in the initializer, but I thought I would at least pass on the info.

When one turns on dynamic finders, it defines a 'respond_to?' method which conflicts with a method of the same named used within other gems like 'socialization'. The result is that the 'rolify' version of respond_to? gets called and causes the other code to fail.

Sorry, but I'm not precisely sure what the best way to fix this myself otherwise, I'd submit some code, but I wanted to let you know.

@EppO
Copy link
Member

EppO commented Jun 7, 2013

Thanks for the feedback.
As rolify calls super in a else statement in the respond_to method (see here), I guess that socialization gem is using the same is_something? method name pattern. So any gem using the same pattern could conflict with rolify, thanks for pointing that out.
Can you try a quick fix on your setup ? change the respond_to? method to this:

def respond_to?(method, include_private = false)
  if Rolify.dynamic_shortcuts && (method.to_s.match(/^is_(\w+)_of[?]$/) || method.to_s.match(/^is_(\w+)[?]$/))
    query = self.class.role_class.where(:name => $1)
    query = self.class.adapter.exists?(query, :resource_type) if method.to_s.match(/^is_(\w+)_of[?]$/)
    return true if query.count > 0
  end
  super
end

@EppO
Copy link
Member

EppO commented Jun 18, 2013

@gitgary did you have a chance to try the workaround in my previous post ?

@gitgary
Copy link
Author

gitgary commented Jun 19, 2013

Hi Florent

Sorry for not responding sooner. Yes, I did try it and yes it seems to be working properly now. It certainly no longer crashes and appears ok. I plan to do a bit more detailed testing however. If I see any odd behavior, I'll be sure to post. Thanks!

@gitgary gitgary closed this as completed Jun 19, 2013
@Alxzu
Copy link

Alxzu commented Jan 24, 2016

@EppO Hi, it seems I'm getting the same error here, can you tell me where I have to put the override code for respond_to? thank you

sampatbadhe added a commit to sampatbadhe/rolify that referenced this issue Dec 25, 2022
…alse for custom model method names starts with is_ and ends with ?
sampatbadhe added a commit to sampatbadhe/rolify that referenced this issue Feb 27, 2023
…alse for custom model method names starts with is_ and ends with ?
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

Successfully merging a pull request may close this issue.

3 participants