Skip to content

Commit d0a9f05

Browse files
committed
Add ModelNames
1 parent 2042156 commit d0a9f05

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/active_interaction/extras.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ def form_for(field_name)
4545
end
4646
end
4747

48+
concern :ModelNames do
49+
class_methods do
50+
def inherited(subclass)
51+
super.tap { subclass.set_model_naming }
52+
end
53+
54+
def set_model_naming
55+
str = name.deconstantize.underscore
56+
model_name.route_key = str.pluralize.to_sym
57+
model_name.singular_route_key = str.singularize.to_sym
58+
end
59+
60+
def singular_resource_route_key!
61+
str = name.deconstantize.underscore
62+
model_name.route_key = str.singularize.to_sym
63+
end
64+
end
65+
end
66+
67+
4868
concern :AfterInitialize do
4969
include ActiveSupport::Callbacks
5070

0 commit comments

Comments
 (0)