Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9234

Show
Ignore:
Timestamp:
04/06/08 18:42:34 (3 months ago)
Author:
josh
Message:

Provide a helper proxy to access helper methods from outside views. Closes #10839 [Josh Peek]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r9226 r9234  
    11*SVN* 
     2 
     3* Provide a helper proxy to access helper methods from outside views. Closes #10839 [Josh Peek] 
     4  e.g. ApplicationController.helpers.simple_format(text) 
    25 
    36* Improve documentation. [Xavier Noria, leethal, jerome] 
  • trunk/actionpack/lib/action_controller/helpers.rb

    r8409 r9234  
    168168      end 
    169169 
     170      # Provides a proxy to access helpers methods from outside the view. 
     171      def helpers 
     172        unless @helper_proxy 
     173          @helper_proxy = ActionView::Base.new 
     174          @helper_proxy.extend master_helper_module 
     175        else 
     176          @helper_proxy 
     177        end 
     178      end 
    170179 
    171180      private 
  • trunk/actionpack/test/controller/helper_test.rb

    r8985 r9234  
    131131  end 
    132132 
     133  def test_helper_proxy 
     134    methods = ApplicationController.helpers.methods.map(&:to_s) 
     135 
     136    # ActionView 
     137    assert methods.include?('pluralize') 
     138 
     139    # abc_helper.rb 
     140    assert methods.include?('bare_a') 
     141 
     142    # fun/games_helper.rb 
     143    assert methods.include?('stratego') 
     144 
     145    # fun/pdf_helper.rb 
     146    assert methods.include?('foobar') 
     147  end 
     148 
    133149  private 
    134150    def expected_helper_methods