-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
display_name_method_for
works not as intended with Draper
#4279
Comments
@faucct , what is your suggestion ? ActiveAdmin provides |
I would suggest removing |
Why didn't you simply solve your problem by overriding |
Are you okay with everyone using decorators solving the problem on their own by copying the code from |
Are you ok with breaking existing behavior? There are many simple ways to solve your problem without copying code or breaking AA. |
Any change is about breaking existing behaviour. Right now I am breaking existing behaviour of
Are you talking about using the |
I'm talking about define a method on your model or decorator. Your decorator breaks the from AR expected behavior by overwriting AR#to_s |
I am not sure if I have understood you here. Are you suggesting me defining a method on a model/decorator to fix the problem or are you explaining to me why the problem is arising? Probably the first one since the problem arises even with no methods defined in the decorator, but I have already answered that it seems weird for an activeadmin user to deal with this. |
Both |
But my decorator does not override anything: it is just an empty decorator with |
Draper defines a |
Yes, and I have stated it at the start of this issue. I am pretty sure that this definition is reasonable and won't be changed inside draper. Are you suggesting that this should be fixed this by putting another guard similar to |
Just define a |
It is a bug in draper, he delegates a method which didn't exist on the decorated object |
|
Yes but for that we have the |
Why you didn't define a |
Well, the check is not perfect and this issue is about it. Do you think we should improve the check, for example if the method is a delegate and the delegated to method does not have a source location? |
Should we really fix a bug of draper in AA? But we can improve the method detection in AA of course. But we should do that in a way that don't depend on a decorator implementation. |
Is it a bug that draper does not override |
The problem is that we can check that if reource.is?(Draper::Decorator)
DISPLAY_NAME_FALLBACK
elsif reource.is?(Foo::Decorator)
...
elsif reource.is?(Bar::Decorator)
...
elsif method != :to_s || resource.method(method).source_location
method
else
DISPLAY_NAME_FALLBACK
end |
We can fix the issue by accepting my PR. The only people affected will be ones relying on |
Many people have models like this:
For that we have the |
What you want is solving your problem by moving the same problem to other people. |
The behaviour of def display_name_method_for(resource)
@@display_name_methods_cache ||= {}
@@display_name_methods_cache[resource.class] ||= begin
methods = active_admin_application.display_name_methods - association_methods_for(resource)
method = methods.detect{ |method| resource.respond_to? method }
if method != :to_s || resource.method(method).source_location
method
end || DISPLAY_NAME_FALLBACK
end
end Now the |
@timoschilling Is the last proposal acceptable if it comes with a test ensuring that the existing behavior you talked about is not broken? |
This is something I think we should revisit. We've run into this issue by just implementing Draper decorators. Everything seems to work fine with that integration across many models but this is the one issue that comes up. The problem becomes we would now have to implement a custom display name across many decorators when all we want is the default behavior. I don't know how easy it would be to do here. |
@javierjulio Did you try @faucct patches, specifically the last one? |
Yes but the result isn't the same. For example, with a multi word named model I noticed the case was different after removing To be clear, just only removing Regarding the patch though, I'm not familiar with the use of the |
I see...
I'm not sure either 🤔 I'll review this in more depth. |
This is the breadcrumb I get while using Draper decorator with
delegate_all
option:ActiveAdmin can not look up the display method name correctly here:
My decorator instance does not respond to any other than
to_s
methods, as the model does. In this case it is supposed to use the fallback, but the problem is that decoratorto_s
method got a source location:["~/.rvm/gems/ruby-2.1.5/gems/draper-2.1.0/lib/draper/delegation.rb", 10]
.The text was updated successfully, but these errors were encountered: