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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs