Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#5809

This is a Rails 3 issue.

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

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'...

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. 99miles
    99miles

    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.

    October 15th, 2010 @ 10:16 PM

  2. captain mike
    captain mike

    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">
    </form>
    

    October 16th, 2010 @ 12:05 PM

  3. captain mike
  4. captain mike
    captain mike

    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]

    October 18th, 2010 @ 08:45 PM

  5. Nicholas Klick
    Nicholas Klick

    This stackoverflow entry outlines the same issue: http://stackoverflow.com/questions/2755337/how-to-render-partial-js...

    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 = Appointment.new
        render :json => {
          :html => render_to_string(
            :partial => 'static/practitioner_fields', 
            :locals => {:practitioners => practitioners, :appointment => @appointment}
          )
        }
    end
    

    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

    January 4th, 2011 @ 07:46 PM

  6. rails
    rails
    • 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.

    April 5th, 2011 @ 01:00 AM

  7. rails
    rails
    • State changed from open to stale

    April 5th, 2011 @ 01:00 AM