David Kahn
2010-Nov-04 15:52 UTC
Re: Train wreck getting render_to_string to work from foreign controller [SOLVED]
Just for collective knowledge as I have found no info on this problem online: I solved this by adding an .html.erb file for the "missing template", since by design or bug Rails3 will not find or render another controllers view (in my experience). Then in the new html.erb file, I just put <%= render "comparisons/display" %> because the views *are* able to find templates from another controller. It seems like this is more work, but I can see that perhaps this was done by design as it forces me to more cleanly define what the controller actions render. On Wed, Nov 3, 2010 at 6:26 PM, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org>wrote:> 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.
Possibly Parallel Threads
- Rails3: render_to_string of a .html.erb when request is a json request raises MissingTemplate error
- rendering a partial inside another using render_to_string and (:formats) in controller
- render_to_string() in a controller that isn''t default route?
- render_to_string inside method shared across several controllers
- Using render_to_string in other custom classes