Skip to content
This repository
Browse code

Changed the default of ActionView#render to assume partials instead o…

…f files when not given an options hash [DHH]
  • Loading branch information...
commit e442448fa3f706062ef9c89912c1fd95e1119f67 2 parents 130fe74 + 27c03e6
David Heinemeier Hansson authored November 19, 2008
2  actionpack/CHANGELOG
@@ -16,6 +16,8 @@
16 16
     # <%= render :partial => "posts/post", :collection => @posts %>
17 17
     <%= render(@posts) %>
18 18
 
  19
+* Remove deprecated render_component. Please use the plugin from http://github.com/rails/render_component/tree/master [Pratik]
  20
+
19 21
 * Fixed RedCloth and BlueCloth shouldn't preload. Instead just assume that they're available if you want to use textilize and markdown and let autoload require them [DHH]
20 22
 
21 23
 
2  actionpack/lib/action_controller.rb
@@ -49,7 +49,6 @@
49 49
 require 'action_controller/streaming'
50 50
 require 'action_controller/session_management'
51 51
 require 'action_controller/http_authentication'
52  
-require 'action_controller/components'
53 52
 require 'action_controller/rack_process'
54 53
 require 'action_controller/record_identifier'
55 54
 require 'action_controller/request_forgery_protection'
@@ -72,7 +71,6 @@
72 71
   include ActionController::Streaming
73 72
   include ActionController::SessionManagement
74 73
   include ActionController::HttpAuthentication::Basic::ControllerMethods
75  
-  include ActionController::Components
76 74
   include ActionController::RecordIdentifier
77 75
   include ActionController::RequestForgeryProtection
78 76
   include ActionController::Translation
2  actionpack/lib/action_controller/base.rb
@@ -529,7 +529,7 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
529 529
       end
530 530
 
531 531
       def send_response
532  
-        response.prepare! unless component_request?
  532
+        response.prepare!
533 533
         response
534 534
       end
535 535
 
169  actionpack/lib/action_controller/components.rb
... ...
@@ -1,169 +0,0 @@
1  
-module ActionController #:nodoc:
2  
-  # Components allow you to call other actions for their rendered response while executing another action. You can either delegate
3  
-  # the entire response rendering or you can mix a partial response in with your other content.
4  
-  #
5  
-  #   class WeblogController < ActionController::Base
6  
-  #     # Performs a method and then lets hello_world output its render
7  
-  #     def delegate_action
8  
-  #       do_other_stuff_before_hello_world
9  
-  #       render_component :controller => "greeter",  :action => "hello_world", :params => { :person => "david" }
10  
-  #     end
11  
-  #   end
12  
-  #
13  
-  #   class GreeterController < ActionController::Base
14  
-  #     def hello_world
15  
-  #       render :text => "#{params[:person]} says, Hello World!"
16  
-  #     end
17  
-  #   end
18  
-  #
19  
-  # The same can be done in a view to do a partial rendering:
20  
-  #
21  
-  #   Let's see a greeting:
22  
-  #   <%= render_component :controller => "greeter", :action => "hello_world" %>
23  
-  #
24  
-  # It is also possible to specify the controller as a class constant, bypassing the inflector
25  
-  # code to compute the controller class at runtime:
26  
-  #
27  
-  # <%= render_component :controller => GreeterController, :action => "hello_world" %>
28  
-  #
29  
-  # == When to use components
30  
-  #
31  
-  # Components should be used with care. They're significantly slower than simply splitting reusable parts into partials and
32  
-  # conceptually more complicated. Don't use components as a way of separating concerns inside a single application. Instead,
33  
-  # reserve components to those rare cases where you truly have reusable view and controller elements that can be employed
34  
-  # across many applications at once.
35  
-  #
36  
-  # So to repeat: Components are a special-purpose approach that can often be replaced with better use of partials and filters.
37  
-  module Components
38  
-    def self.included(base) #:nodoc:
39  
-      base.class_eval do
40  
-        include InstanceMethods
41  
-        include ActiveSupport::Deprecation
42  
-        extend ClassMethods
43  
-        helper HelperMethods
44  
-
45  
-        # If this controller was instantiated to process a component request,
46  
-        # +parent_controller+ points to the instantiator of this controller.
47  
-        attr_accessor :parent_controller
48  
-
49  
-        alias_method_chain :process_cleanup, :components
50  
-        alias_method_chain :set_session_options, :components
51  
-        alias_method_chain :flash, :components
52  
-
53  
-        alias_method :component_request?, :parent_controller
54  
-      end
55  
-    end
56  
-
57  
-    module ClassMethods
58  
-      # Track parent controller to identify component requests
59  
-      def process_with_components(request, response, parent_controller = nil) #:nodoc:
60  
-        controller = new
61  
-        controller.parent_controller = parent_controller
62  
-        controller.process(request, response)
63  
-      end
64  
-    end
65  
-
66  
-    module HelperMethods
67  
-      def render_component(options)
68  
-        @controller.__send__(:render_component_as_string, options)
69  
-      end
70  
-    end
71  
-
72  
-    module InstanceMethods
73  
-      # Extracts the action_name from the request parameters and performs that action.
74  
-      def process_with_components(request, response, method = :perform_action, *arguments) #:nodoc:
75  
-        flash.discard if component_request?
76  
-        process_without_components(request, response, method, *arguments)
77  
-      end
78  
-
79  
-      protected
80  
-        # Renders the component specified as the response for the current method
81  
-        def render_component(options) #:doc:
82  
-          component_logging(options) do
83  
-            render_for_text(component_response(options, true).body, response.headers["Status"])
84  
-          end
85  
-        end
86  
-        deprecate :render_component => "Please install render_component plugin from http://github.com/rails/render_component/tree/master"
87  
-
88  
-        # Returns the component response as a string
89  
-        def render_component_as_string(options) #:doc:
90  
-          component_logging(options) do
91  
-            response = component_response(options, false)
92  
-
93  
-            if redirected = response.redirected_to
94  
-              render_component_as_string(redirected)
95  
-            else
96  
-              response.body
97  
-            end
98  
-          end
99  
-        end
100  
-        deprecate :render_component_as_string => "Please install render_component plugin from http://github.com/rails/render_component/tree/master"
101  
-
102  
-        def flash_with_components(refresh = false) #:nodoc:
103  
-          if !defined?(@_flash) || refresh
104  
-            @_flash =
105  
-              if defined?(@parent_controller)
106  
-                @parent_controller.flash
107  
-              else
108  
-                flash_without_components
109  
-              end
110  
-          end
111  
-          @_flash
112  
-        end
113  
-
114  
-      private
115  
-        def component_response(options, reuse_response)
116  
-          klass    = component_class(options)
117  
-          request  = request_for_component(klass.controller_name, options)
118  
-          new_response = reuse_response ? response : response.dup
119  
-
120  
-          klass.process_with_components(request, new_response, self)
121  
-        end
122  
-
123  
-        # determine the controller class for the component request
124  
-        def component_class(options)
125  
-          if controller = options[:controller]
126  
-            controller.is_a?(Class) ? controller : "#{controller.camelize}Controller".constantize
127  
-          else
128  
-            self.class
129  
-          end
130  
-        end
131  
-
132  
-        # Create a new request object based on the current request.
133  
-        # The new request inherits the session from the current request,
134  
-        # bypassing any session options set for the component controller's class
135  
-        def request_for_component(controller_name, options)
136  
-          new_request         = request.dup
137  
-          new_request.session = request.session
138  
-
139  
-          new_request.instance_variable_set(
140  
-            :@parameters,
141  
-            (options[:params] || {}).with_indifferent_access.update(
142  
-              "controller" => controller_name, "action" => options[:action], "id" => options[:id]
143  
-            )
144  
-          )
145  
-
146  
-          new_request
147  
-        end
148  
-
149  
-        def component_logging(options)
150  
-          if logger
151  
-            logger.info "Start rendering component (#{options.inspect}): "
152  
-            result = yield
153  
-            logger.info "\n\nEnd of component rendering"
154  
-            result
155  
-          else
156  
-            yield
157  
-          end
158  
-        end
159  
-
160  
-        def set_session_options_with_components(request)
161  
-          set_session_options_without_components(request) unless component_request?
162  
-        end
163  
-
164  
-        def process_cleanup_with_components
165  
-          process_cleanup_without_components unless component_request?
166  
-        end
167  
-    end
168  
-  end
169  
-end
2  actionpack/lib/action_controller/flash.rb
@@ -165,7 +165,7 @@ def flash(refresh = false) #:doc:
165 165
         def assign_shortcuts_with_flash(request, response) #:nodoc:
166 166
           assign_shortcuts_without_flash(request, response)
167 167
           flash(:refresh)
168  
-          flash.sweep if @_session && !component_request?
  168
+          flash.sweep if @_session
169 169
         end
170 170
     end
171 171
   end
152  actionpack/test/controller/components_test.rb
... ...
@@ -1,152 +0,0 @@
1  
-require 'abstract_unit'
2  
-
3  
-class CallerController < ActionController::Base
4  
-  def calling_from_controller
5  
-    render_component(:controller => "callee", :action => "being_called")
6  
-  end
7  
-
8  
-  def calling_from_controller_with_params
9  
-    render_component(:controller => "callee", :action => "being_called", :params => { "name" => "David" })
10  
-  end
11  
-
12  
-  def calling_from_controller_with_different_status_code
13  
-    render_component(:controller => "callee", :action => "blowing_up")
14  
-  end
15  
-
16  
-  def calling_from_template
17  
-    render :inline => "Ring, ring: <%= render_component(:controller => 'callee', :action => 'being_called') %>"
18  
-  end
19  
-
20  
-  def internal_caller
21  
-    render :inline => "Are you there? <%= render_component(:action => 'internal_callee') %>"
22  
-  end
23  
-
24  
-  def internal_callee
25  
-    render :text => "Yes, ma'am"
26  
-  end
27  
-
28  
-  def set_flash
29  
-    render_component(:controller => "callee", :action => "set_flash")
30  
-  end
31  
-
32  
-  def use_flash
33  
-    render_component(:controller => "callee", :action => "use_flash")
34  
-  end
35  
-
36  
-  def calling_redirected
37  
-    render_component(:controller => "callee", :action => "redirected")
38  
-  end
39  
-
40  
-  def calling_redirected_as_string
41  
-    render :inline => "<%= render_component(:controller => 'callee', :action => 'redirected') %>"
42  
-  end
43  
-
44  
-  def rescue_action(e) raise end
45  
-end
46  
-
47  
-class CalleeController < ActionController::Base
48  
-  def being_called
49  
-    render :text => "#{params[:name] || "Lady"} of the House, speaking"
50  
-  end
51  
-
52  
-  def blowing_up
53  
-    render :text => "It's game over, man, just game over, man!", :status => 500
54  
-  end
55  
-
56  
-  def set_flash
57  
-    flash[:notice] = 'My stoney baby'
58  
-    render :text => 'flash is set'
59  
-  end
60  
-
61  
-  def use_flash
62  
-    render :text => flash[:notice] || 'no flash'
63  
-  end
64  
-
65  
-  def redirected
66  
-    redirect_to :controller => "callee", :action => "being_called"
67  
-  end
68  
-
69  
-  def rescue_action(e) raise end
70  
-end
71  
-
72  
-class ComponentsTest < ActionController::TestCase
73  
-  tests CallerController
74  
-
75  
-  def test_calling_from_controller
76  
-    assert_deprecated do
77  
-      get :calling_from_controller
78  
-      assert_equal "Lady of the House, speaking", @response.body
79  
-    end
80  
-  end
81  
-
82  
-  def test_calling_from_controller_with_params
83  
-    assert_deprecated do
84  
-      get :calling_from_controller_with_params
85  
-      assert_equal "David of the House, speaking", @response.body
86  
-    end
87  
-  end
88  
-
89  
-  def test_calling_from_controller_with_different_status_code
90  
-    assert_deprecated do
91  
-      get :calling_from_controller_with_different_status_code
92  
-      assert_equal 500, @response.response_code
93  
-    end
94  
-  end
95  
-
96  
-  def test_calling_from_template
97  
-    assert_deprecated do
98  
-      get :calling_from_template
99  
-      assert_equal "Ring, ring: Lady of the House, speaking", @response.body
100  
-    end
101  
-  end
102  
-
103  
-  def test_etag_is_set_for_parent_template_when_calling_from_template
104  
-    assert_deprecated do
105  
-      get :calling_from_template
106  
-      expected_etag = etag_for("Ring, ring: Lady of the House, speaking")
107  
-      assert_equal expected_etag, @response.headers['ETag']
108  
-    end
109  
-  end
110  
-
111  
-  def test_internal_calling
112  
-    assert_deprecated do
113  
-      get :internal_caller
114  
-      assert_equal "Are you there? Yes, ma'am", @response.body
115  
-    end
116  
-  end
117  
-
118  
-  def test_flash
119  
-    assert_deprecated do
120  
-      get :set_flash
121  
-      assert_equal 'My stoney baby', flash[:notice]
122  
-      get :use_flash
123  
-      assert_equal 'My stoney baby', @response.body
124  
-      get :use_flash
125  
-      assert_equal 'no flash', @response.body
126  
-    end
127  
-  end
128  
-
129  
-  def test_component_redirect_redirects
130  
-    assert_deprecated do
131  
-      get :calling_redirected
132  
-      assert_redirected_to :controller=>"callee", :action => "being_called"
133  
-    end
134  
-  end
135  
-
136  
-  def test_component_multiple_redirect_redirects
137  
-    test_component_redirect_redirects
138  
-    test_internal_calling
139  
-  end
140  
-
141  
-  def test_component_as_string_redirect_renders_redirected_action
142  
-    assert_deprecated do
143  
-      get :calling_redirected_as_string
144  
-      assert_equal "Lady of the House, speaking", @response.body
145  
-    end
146  
-  end
147  
-
148  
-  protected
149  
-    def etag_for(text)
150  
-      %("#{Digest::MD5.hexdigest(text)}")
151  
-    end
152  
-end

0 notes on commit e442448

Please sign in to comment.
Something went wrong with that request. Please try again.