David Kahn
2010-Nov-04 00:26 UTC
Train wreck getting render_to_string to work from foreign controller
I am calling render_to_string on an action of a different controller. I am not sure if this is just in Rails 3 (I am using) or if it would have presented in previous versions. I especially don''t understand why this method should ignore :controller => "xx" and assume the current controller. Here are a few of the trials and results: *html_to_save = render_to_string(:action => "/comparisons#display", :layout => "application")* *returns* (in addition to a deprication error)*:* ActionView::MissingTemplate: Missing template /comparisons#display with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/Users/DK/Documents/ror/projects/creditcompare3/app/views" * html_to_save = render_to_string(:action => "/comparisons/display", :layout => "application") *returns: ActionView::Template::Error: Missing partial web_requests/display with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/Users/DK/Documents/ror/projects/creditcompare3/app/views" *html_to_save = render_to_string(:controller => "comparisons", :action => "display", :layout => "application") returns*: ActionView::MissingTemplate: Missing template web_requests/display with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/Users/DK/Documents/ror/projects/creditcompare3/app/views" * html_to_save = render_to_string(:action => "display", :layout => "application") returns* (obviously): ActionView::MissingTemplate: Missing template web_requests/display with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "/Users/DK/Documents/ror/projects/creditcompare3/app/views" In the Rails source I find: # Raw rendering of a template to a string. Just convert the results of # render_to_body into a String. # :api: plugin def render_to_string(*args, &block) options = _normalize_args(*args, &block) _normalize_options(options) render_to_body(options) end # Raw rendering of a template to a Rack-compatible body. # :api: plugin def render_to_body(options = {}) _process_options(options) _render_template(options) end # Find and renders a template based on the options given. # :api: private def _render_template(options) #:nodoc: view_context.render(options) end So I new to reading the source but is the problem that it is using the view_context which I would assume would be that which the current controller owns? That would seems to confirm the errors and ignorance of the controller attribute. Thanks, David -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.