Skip to content

Instantly share code, notes, and snippets.

@olegantonyan
Last active August 29, 2015 14:25
Show Gist options
  • Save olegantonyan/27ebfbf3ea058509d4e8 to your computer and use it in GitHub Desktop.
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)
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