You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've come across a situation where the CollectionResponder improperly (for me) produces collection routes that include the full namespace of a model for the route_key. I've overridden this in my app to the following:
def navigation_location
return options[:location] if options[:location]
klass = resources.last.class
if klass.respond_to?(:model_name)
model_name = ActiveModel::Name.new(klass, klass.module_parent)
resources[0...-1] << model_name.route_key.to_sym
else
resources
end
end
Specifically I've changed: model_name = ActiveModel::Name.new(klass, klass.module_parent) (Rails 6.1+ I believe) so that it returns a model_name object that has been passed in the module_parent namespace. This results in the route_key being namespaceless.
For example I had respond_with :admin, form, submission in my destroy method for submissions. Submission is a model: Forms::Submission and I wanted a route admin_form_submissions_path but was getting admin_form_form_submissions_path because of the namespace.
I've fixed it for me, but wondered if you think it's worth allowing it to be configurable for this responder?
The text was updated successfully, but these errors were encountered:
I've come across a situation where the
CollectionResponder
improperly (for me) produces collection routes that include the full namespace of a model for theroute_key
. I've overridden this in my app to the following:Specifically I've changed:
model_name = ActiveModel::Name.new(klass, klass.module_parent)
(Rails 6.1+ I believe) so that it returns a model_name object that has been passed in themodule_parent
namespace. This results in theroute_key
being namespaceless.For example I had
respond_with :admin, form, submission
in mydestroy
method forsubmissions
. Submission is a model:Forms::Submission
and I wanted a routeadmin_form_submissions_path
but was gettingadmin_form_form_submissions_path
because of the namespace.I've fixed it for me, but wondered if you think it's worth allowing it to be configurable for this responder?
The text was updated successfully, but these errors were encountered: