rails: Missing template error message when actually missing partial

This bug only occurs in Rails 3.2.1 (not 3.1.3) when passing the format in the template name.

To reproduce:

  1. Generate a fresh Rails 3.2.1 project
  2. Register PDF as MIME-type and uncomment the catch-all route
  3. Generate a controller with the following content: app/controllers/welcome_controller.rb
class WelcomeController < ApplicationController
  def index
    respond_to do |format|
      format.html
      format.pdf do
        render :formats => [:html]
      end
    end
  end
end

app/views/welcome/index.html:

Test!

<%= render 'missing', :formats => [:html] %>

On /welcome/index.html:

Missing partial welcome/missing, application/missing with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
  * "/Users/user/Documents/render_to_string_bug/app/views"

This is correct.

On /welcome/index.pdf:

Template is missing

Missing template welcome/index with {:locale=>[:en], :formats=>[:pdf], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/user/Documents/render_to_string_bug/app/views"

This last error message, however, is incorrect: the partial is missing, not the template.

On a related note, with Rails 3.1.3 I could implicitly render a .html partial with render 'partial_name' when rendering welcome/index.pdf in the above example. Do I have to use an explicit :formats => [:html] from now on with Rails 3.2.1?

By the way, the example above is contrived, but I wanted to show the simplest case in which the error occurs. I use render_to_string and send_data to render the html to pdf, so I only render .html templates and partials within the format.pdf block.

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 19 (13 by maintainers)

Commits related to this issue

Most upvoted comments

The issue should be fixes but one thing the proper way to render a partial is …

<%= render :partial => 'missing', :formats => [:html] %>

I know is a bit odd but we can’t make it work because it would break backwards compatibility

Let me know if after this patch everything works ok for you