Last active
August 29, 2015 14:25
-
-
Save olegantonyan/27ebfbf3ea058509d4e8 to your computer and use it in GitHub Desktop.
Monkey patch to_partial_path to fix namespaced models (https://github.com/rails/rails/issues/21004)
This file contains 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
module ActiveModel | |
module Conversion | |
def to_partial_path | |
original_path = self.class._to_partial_path | |
parts = original_path.split('/') | |
return original_path if parts.length == 2 | |
pluralized_parts = parts[0..-3].map { |p| p.pluralize } | |
"#{pluralized_parts.join('/')}/#{parts.last(2).join('/')}".freeze | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment