File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,9 @@ module ClassMethods # :nodoc:
108
108
# Provide a class level cache for #to_partial_path. This is an
109
109
# internal method and should not be accessed directly.
110
110
def _to_partial_path # :nodoc:
111
- @_to_partial_path ||= begin
111
+ @_to_partial_path ||= if respond_to? ( :model_name )
112
+ "#{ model_name . collection } /#{ model_name . element } "
113
+ else
112
114
element = ActiveSupport ::Inflector . underscore ( ActiveSupport ::Inflector . demodulize ( name ) )
113
115
collection = ActiveSupport ::Inflector . tableize ( name )
114
116
"#{ collection } /#{ element } "
Original file line number Diff line number Diff line change @@ -58,6 +58,10 @@ def persisted?
58
58
assert_equal "helicopter/comanches/comanche" , Helicopter ::Comanche . new . to_partial_path
59
59
end
60
60
61
+ test "to_partial_path handles non-standard model_name" do
62
+ assert_equal "attack_helicopters/ah-64" , Helicopter ::Apache . new . to_partial_path
63
+ end
64
+
61
65
test "#to_param_delimiter allows redefining the delimiter used in #to_param" do
62
66
old_delimiter = Contact . param_delimiter
63
67
Contact . param_delimiter = "_"
Original file line number Diff line number Diff line change @@ -7,3 +7,16 @@ class Helicopter
7
7
class Helicopter ::Comanche
8
8
include ActiveModel ::Conversion
9
9
end
10
+
11
+ class Helicopter ::Apache
12
+ include ActiveModel ::Conversion
13
+
14
+ class << self
15
+ def model_name
16
+ @model_name ||= ActiveModel ::Name . new ( self ) . tap do |model_name |
17
+ model_name . collection = "attack_helicopters"
18
+ model_name . element = "ah-64"
19
+ end
20
+ end
21
+ end
22
+ end
You can’t perform that action at this time.
0 commit comments