Ruby on Rails
Monday, April 10, 2017
While playing around with gem `traceroute` (0.5.0) I noticed that my additional flash types:
are "leaking" into public scope of every controller descendent of ApplicationController:
-- # application_controller.rb
# ...
add_flash_types :successadd_flash_types :error
# ...
are "leaking" into public scope of every controller descendent of ApplicationController:
ApplicationController.new.method(:error).source_location
ApplicationController.new.method(:success).source_location
I wonder if add_flash_types should define the new methods as protected, since it might lead into conflicts with actual controller actions.
You can see this "leaking" with the gem or just with this:
ApplicationController.descendants.map { |ctrl| ctrl.action_methods.map { |action| ctrl.name + "#" + action }}.flatten
This is trivial to accomplish - simply change it to:
#...
define_method(type) do request.flash[type]end
protected typehelper_method type
#...
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/cd6a1b49-fd4c-45d3-ad89-4f3bd019b78e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment