This project is archived and is in readonly mode.

#5809 ✓stale
captain mike

'template is missing' when trying to use render_to_string in controller#action

Reported by captain mike | October 14th, 2010 @ 04:05 PM

This is a Rails 3 issue.

def index
  partial = render_to_string(:partial => 'partial_name', :locals => {...})
  respond_to do |format|
    format.js { render :json => {...} }

Hitting the 'index' action from browser results in 'Template is missing' error on the partial_name given.
However, no error occurs when hitting the action from functional test.

get :index, :format => 'js'

One 'fix' is to use 'partial_name.html'...

Comments and changes to this ticket

  • 99miles

    99miles October 15th, 2010 @ 10:16 PM

    Is your partial .erb or .haml? It's working fine for me with a basic erb partial. I'm wondering if there's something more specific about this.

  • captain mike

    captain mike October 16th, 2010 @ 12:05 PM

    hi, thx for looking into this.

    this is the form that triggers the submit. Hope this can provide some insight.

    <form method="get" data-type="json" data-remote="true" action="/products/search" accept-charset="UTF-8"><div style="margin: 0pt; padding: 0pt; display: inline;"><input type="hidden" value="✓" name="utf8"></div>   <label for="Search">Search</label>
        <input type="text" name="keyword" id="keyword">
  • captain mike
  • captain mike

    captain mike October 18th, 2010 @ 08:45 PM

    it looks to be related to :formats, a request for 'json' from browser yields:
    Missing partial products/search/results with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:json, :js, :"/"]

    from the functional test,
    get :search, :keyword => 'abcdef', :format => 'js' would work as :formats=>[:js, :html]

  • Nicholas Klick

    Nicholas Klick January 4th, 2011 @ 07:46 PM

    This stackoverflow entry outlines the same issue:

    I also am seeing this error with Rails 3.0.1 but curiously not in every browser.

    def choose
        practitioners = Service.find(params[:id]).practitioners
        @appointment =
        render :json => {
          :html => render_to_string(
            :partial => 'static/practitioner_fields', 
            :locals => {:practitioners => practitioners, :appointment => @appointment}

    I am posting to the "/choose" action via ajax and trying to render a partial (named _practitioner_fields.html.erb) JSON back and update HTML. Typically this method works in every browser. The above works in FireFox but not in Chrome, IE etc, where I get the following error:

    ActionView::MissingTemplate (Missing partial static/practitioner_fields with {:handlers=>[:rjs, :rhtml, :builder, :rxml, :erb], :locale=>[:en, :en], :formats=>[:json, :js, :"/"]} in view paths "/app/views"):
    app/controllers/static_controller.rb:17:in choose'

    The partial contains html thus needs to be the html type.

    Interesting if I change the name of my partial to _practitioner_fields.rhtml, there is no error in any browser and the ajax returns the correct response and updates the DOM

  • rails

    rails April 5th, 2011 @ 01:00 AM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails April 5th, 2011 @ 01:00 AM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>