rails/rails — pull request #6990 by mirceapricop (2012-07-06 16:12:44+00:00)
Title: Fix: Mime type names conflict with method names

We discovered this issue in one of our production apps, because we tried to use `touch` as a custom mime type, which led to the `touch` method of `Object` being executed sometimes, causing vexing errors.

This is the case for any mime type with the same name as a method on Object, even private ones.

This is caused by the following execution path:

1. `respond_to :touch` is called in a controller. This adds `:touch` to the list of mimes.
2. `retrieve_collector_from_mimes` calls `Collector.new(mimes)`
3. `initialize` calls `mimes.each { |mime| send(mime) }`
4. `send(:touch)`, instead of triggering `method_missing` on the `AbstractController::Collector`, actually calls `Object.touch`. This can lead to any sort of behavior.

A proposed fix for this issue is attached. It is based on generating the required methods on `Collector` after each mime type is registered, instead of relying on `method_missing`. That way, `send` always hits them instead of going up to `Object`.

Check out the commit messages for more info.