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
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
..
abstract_controller Move protected instance variable to the right place 2016-05-05 11:18:10 -05:00
action_controller Implement helpers proxy in controller instance level 2016-05-05 16:17:17 -05:00
action_dispatch Ensure compatibility between ActionDispatch::Request::Session and Rack 2016-05-04 15:49:25 -04:00
action_pack Prep Rails 5 beta 4 2016-04-27 15:48:47 -05:00
abstract_controller.rb Move Caching module to Abstract Controller 2016-02-23 21:11:15 -03:00
action_controller.rb Move Caching module to Abstract Controller 2016-02-23 21:11:15 -03:00
action_dispatch.rb Publish AS::Executor and AS::Reloader APIs 2016-03-02 02:14:20 +10:30
action_pack.rb Update copyright notices to 2016 [ci skip] 2015-12-31 18:27:19 +02:00