translation_lookup_prefix for records decorated by draper#18
Open
karwank wants to merge 1 commit intohunterae:masterfrom
Open
translation_lookup_prefix for records decorated by draper#18karwank wants to merge 1 commit intohunterae:masterfrom
karwank wants to merge 1 commit intohunterae:masterfrom
Conversation
hunterae
reviewed
Oct 15, 2019
lib/table_for/base.rb
Outdated
| def translation_lookup_prefix | ||
| if global_options[:records].respond_to?(:model) | ||
| "activerecord.attributes.#{global_options[:records].model.to_s.underscore}" | ||
| elsif global_options[:records].all? {|record| record.is_a?(ApplicationDecorator) && record.class == global_options[:records].first.class && record.respond_to?(:object) } |
Owner
There was a problem hiding this comment.
This will break if the application does not have ApplicationDecorator defined. Perhaps the elsif should start with something like:
elsif defined?(ApplicationDecorator) && global_options[:records].all? {|record| record.is_a?(ApplicationDecorator) && record.class == global_options[:records].first.class && record.respond_to?(:object) }This would also be dependent on whether ApplicationDecorator is expected to exist when using the draper gem (which I haven't used in several years so I can't remember).
Also, please add a test case to handle this scenario.
03affbd to
b26afce
Compare
Contributor
Author
|
Yes, you are right. I forgot that it may crash when ApplicationDecorator class is not defined. I also realized that ApplicationDecorator is only an extension of Draper::Decorator so I changed it according to your suggestion. Sorry, I don't know how to write such test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When draper gem is used to decorate models in controller translation_lookup_prefix method creates wrong path to the translation.