1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_controller
Rafael Mendonça França 541a51ecf8 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
2016-05-05 16:17:17 -05:00
..
api Re-add ActionController::ApiRendering 2016-01-20 19:16:23 -05:00
metal Implement helpers proxy in controller instance level 2016-05-05 16:17:17 -05:00
railties
api.rb quick edits on the AC::API RDoc [ci skip] 2016-04-05 11:06:09 -04:00
base.rb Implement helpers proxy in controller instance level 2016-05-05 16:17:17 -05:00
caching.rb Move private methods to the private visibility 2016-02-24 00:08:01 -03:00
form_builder.rb remove extra = in form builder example [ci skip] 2015-04-15 23:06:01 +09:00
log_subscriber.rb log_process_action will return an array, so use empty? 2016-02-09 13:48:03 -08:00
metal.rb partially revert 69009f4473 2016-02-17 14:01:19 -08:00
railtie.rb Merge pull request #15933 from rafael/master 2014-06-27 18:16:52 -03:00
renderer.rb Merge pull request #24845 from tomkadwill/action_controller_typos 2016-05-04 01:07:24 -05:00
template_assertions.rb Remove assigns and assert_template. 2015-05-30 14:13:57 +08:00
test_case.rb Change 'a HTTP' to 'an HTTP' [ci skip] 2016-03-03 20:28:01 +05:30