aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/database_statements_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2016-05-05 12:02:28 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2016-05-05 16:17:17 -0500
commit541a51ecf8ee04f956b7d8efb13935640aa831ce (patch)
tree6345e2f9dc8ab3db011a7eed0a001c43438e7fa0 /activerecord/test/cases/database_statements_test.rb
parentcece50d3a6b432f848ca04a92da331f8b032d51f (diff)
downloadrails-541a51ecf8ee04f956b7d8efb13935640aa831ce.tar.gz
rails-541a51ecf8ee04f956b7d8efb13935640aa831ce.tar.bz2
rails-541a51ecf8ee04f956b7d8efb13935640aa831ce.zip
Implement helpers proxy in controller instance level
It is a common pattern in the Rails community that when people want to :xa use any kind of helper that is defined inside app/helpers they includes the helper module inside the controller like: module UserHelper def my_user_helper # ... end end class UsersController < ApplicationController include UserHelper def index render inline: my_user_helper end end This has problem because the helper can't access anything that is defined in the view level context class. Also all public methods of the helper become available in the controller what can lead to undesirable methods being routed and behaving as actions. Also if you helper depends on other helpers or even Action View helpers you need to include each one of these dependencies in your controller otherwise your helper is not going to work. We already have a helpers proxy at controller class level but that proxy doesn't have access to the instance variables defined in the controller. With this new instance level helper proxy users can reuse helpers in the controller without having to include the modules and with access to instance variables defined in the controller. class UsersController < ApplicationController def index render inline: helpers.my_user_helper end end
Diffstat (limited to 'activerecord/test/cases/database_statements_test.rb')
0 files changed, 0 insertions, 0 deletions