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:
- Generate a fresh Rails 3.2.1 project
- Register PDF as MIME-type and uncomment the catch-all route
- 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
- Use the right format when a partial is missing. Closes #5025 — committed to kennyj/rails by spastorino 12 years ago
- format lookup for partials is derived from the format in which the template is being rendered Closes #5025 part 2 — committed to spastorino/rails by spastorino 12 years ago
- format lookup for partials is derived from the format in which the template is being rendered Closes #5025 part 2 — committed to arunagw/rails by spastorino 12 years ago
The issue should be fixes but one thing the proper way to render a partial is …
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