New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected controller prefix path de-duplication in view partial lookup paths #50916
Comments
I've reviewed the history of this code and it's not clear what the intended behaviour should be. The original implementation of The logic changed in 2995134 to add a There is very little test coverage to explain what behaviour the authors intended to support, and the behaviour as currently implemented is arguably wrong and at best confusing for users. The case we could like to see addressed is where a controller has a module prefix that is not present on the object path, example above is a bit contrived, but I suspect many developers will have controllers in merge_prefix_into_object_path("admin/quiz/questions_controller", "quiz/questions/_question.html.erb")
# => `admin/quiz/questions/_question.html.erb` An alternative implementation would look for overlap at the end of the controller path and the beginning of the object path, and remove any duplication it detects. Here's an example implementation: prefixes = []
prefix_array = File.dirname(prefix).split("/")
prefix_array.each_with_index do |dir, index|
break if object_path.start_with?(prefix_array[index..-1].join("/"))
prefixes << dir
end
(prefixes << object_path).join("/") I'd be happy to provide a PR if this behaviour is acceptable. |
Previous discussion from 2011: #1951 |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
I can still reproduce this on 7-1 and main. Could I get someone's eyes over it? It's a simple fix, so if there's appetite I'd be happy to provide a PR for consideration. |
Steps to reproduce
Create nested controller and nested object views where there is overlap between the controller and object namespaces. For example:
Courses::Quiz::Question
andCourses::Quiz::QuestionsController
Courses::Quiz::Question
andLearning::Quiz::Extra::QuestionsController
Courses::Quiz::Question
andLearning::Courses::Quiz::QuestionsController
Expected behavior
module duplication is detected and removed
quiz/extra
suffix on the controller does not match thequiz
prefix on the model so no de-duplication is performed. Partial should belearning/courses/extra/courses/quiz/questions/_question.html.erb
courses/quiz
suffix on controller matchescourses/quiz
prefix on model so repetition is removed. Partial should belearning/courses/quiz/questions/_question.html.erb
Actual behavior
module duplication is detected and removed
Quiz
is detected as overlap andExtra
is dropped from the partial path, this is confusing and inconsistentno module duplication is detected, so full module path to controller is prefixed on the object path – deep repetition
System configuration
Rails version: 7.1.0
Ruby version: 3.2.3
The text was updated successfully, but these errors were encountered: