Comments (2)
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.
Previous discussion from 2011: #1951
from rails.
Related Issues (20)
- Configuration of config.i18n.fallbacks is not working HOT 2
- ActiveRecord::Encryption is encrypting/filtering other similar named attributes HOT 7
- Running "rails new app" fails causes a JSON LoadError HOT 4
- has_many relation with joins adding redundant inverse inner join HOT 2
- Structuring the Active Record Query Guide HOT 15
- ActionCable::Channel::Broadcasting.serialize_broadcasting leads to unintentional very wide broadcast
- ActiveRecord.upset generates a databases warning with MySQL 8
- ActionText::RichText attachments not cleaned up when content made empty HOT 1
- add a better interface to the issues tab on this repo HOT 1
- Unnecessary auto save is triggered for polymorphic has_one defined in child class using single-table inheritance HOT 3
- ActiveStorage ProxyController sets Cache-Control headers on errors like FileNotFoundError HOT 3
- Using preload with composite keys can cause too many records to be read HOT 3
- Empty multipart form data raises ActionController::BadRequest error since Rails 7.0.5 HOT 6
- Incompatible with nio4r 2.5.8 gem when running Bundle Install (Rails version 7.0.5.1) HOT 2
- Can't use Model.exists? with composite primary keys HOT 1
- Missing Active Record encryption credential when using ActiveRecord::Encryption.without_encryption HOT 1
- Forked child processes created through rails runner throw error from ActiveRecord when exiting HOT 3
- Add .default method to ActiveSupport::ParameterFilter (syntax sugar) HOT 2
- RedisCacheStore not fault tolerant (as I expected) HOT 3
- Doc have typo? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails.