What is the difference between ActionView::Base#render and ActionController::Base#render? When is each one used? I ask because I need to modify the render code, but can''t for the life of me figure out how its working. For example, if I copy ActionController::Base#render character for character from the Rails source, and put this in application.rb, class ActionController::Base # insert copied render code here, make no modificatoins end Then all of a sudden my app starts rendering differently -- all layout informatoin is gone, and all I get is the raw text from the action. Even though the code is the same character for character from the source tree. Furthermore, I puts RAILS_DEFAULT_LOGGER.puts statements in any section of *both* renders which look like they handle the rending of partials, and yet when I call a page with a partial, I never see my logger statements. Not once. I''m completely lost here.
A had a long journey down this path today, because I was trying to figure out why I couldn''t use :inline => and :locals => {} in the same render statement. (Simple answer: you can''t. Anyone interested in changing that? It would be a pretty easy patch.) ActionController:Base#render is called when you invoke render() from a controller, and ActionView''s version is invoked from helpers and views. Also, having seen the semi-convoluted execution path, I''d like to recommend that you consider overriding one of the more specific methods, like render_file or render_template. I''d imagine that your copy-and-paste didn''t work because you''d actually want to override the class method, rather than creating a new instance method called "render", though I haven''t tried, so I''m just guessing. A good way to make sure you can see test statements on the console is to use "warn" instead of "puts". Oh, and you''ll need to restart Webrick after changing any of the Rails ''vendor'' code. Belorion wrote:> What is the difference between ActionView::Base#render and > ActionController::Base#render? When is each one used? I ask because > I need to modify the render code, but can''t for the life of me figure > out how its working. > > For example, if I copy ActionController::Base#render character for > character from the Rails source, and put this in application.rb, > > class ActionController::Base > # insert copied render code here, make no modificatoins > end > > Then all of a sudden my app starts rendering differently -- all layout > informatoin is gone, and all I get is the raw text from the action. > Even though the code is the same character for character from the > source tree. > > Furthermore, I puts RAILS_DEFAULT_LOGGER.puts statements in any > section of *both* renders which look like they handle the rending of > partials, and yet when I call a page with a partial, I never see my > logger statements. Not once. I''m completely lost here.
On Aug 2, 2005, at 4:42 PM, Belorion wrote:> What is the difference between ActionView::Base#render and > ActionController::Base#render? When is each one used? I ask because > I need to modify the render code, but can''t for the life of me figure > out how its working. >I''m not sure of the internal details, but ActionController::Base#render is the method called from within your controllers. For example, if you call render :text => "Hello World" from within an action, then that is the render method being called. On the other hand, ActionView::Base#render is responsible for render calls from within the views themselves, e.g.: <%= render :partial => "user" %>> For example, if I copy ActionController::Base#render character for > character from the Rails source, and put this in application.rb, > > class ActionController::Base > # insert copied render code here, make no modificatoins > end> Then all of a sudden my app starts rendering differently -- all layout > informatoin is gone, and all I get is the raw text from the action. > Even though the code is the same character for character from the > source tree. >Hmm, that is strange. Anyone have any ideas?> Furthermore, I puts RAILS_DEFAULT_LOGGER.puts statements in any > section of *both* renders which look like they handle the rending of > partials, and yet when I call a page with a partial, I never see my > logger statements. Not once. I''m completely lost here.I usually use RAILS_DEFAULT_LOGGER.warn or .error... does that make any difference? Good luck, Duane Johnson (canadaduane)
> Hmm, that is strange. Anyone have any ideas?because render isn''t actually render. Have a look at the alias_method calls in: http://dev.rubyonrails.org/file/trunk/actionpack/lib/action_controller/layout.rb Overriding render is a little trickier than you think. -- Cheers Koz