Git Product home page Git Product logo

Comments (2)

sfnelson avatar sfnelson commented on June 28, 2024

I've reviewed the history of this code and it's not clear what the intended behaviour should be.

The original implementation of ActionView::PartialRenderer#merge_path_into_partial introduced in dc1b0fd would remove any tokens that were repeated at the same position, so example 2 (Courses::Quiz::Question and Learning::Quiz::Extra::QuestionsController) would work as described.

The logic changed in 2995134 to add a break as soon as the first overlapping module was detected, but this ignores any subsequent modules, and only requires that the module depth is the same. This is the behaviour that still exists today.

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 Admin modules. The additional prefix means that controller/object de-duplication does not work because the relative offsets are different.

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.

from rails.

sfnelson avatar sfnelson commented on June 28, 2024

Previous discussion from 2011: #1951

from rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.