Render doesn't find an html.erb file when called from a xml/atom builder?

I’m trying to put together an atom feed. In trying to keep things DRY
it seemed to make sense to render each item in the feed with the same
html partial that we used to render it on our website. Unfortunately
render doesn’t seem able to find the template.

More specifically let’s say my controller has an action like this:

def index
@topics = Datasource.list
respond_to do |wants|
wants.html
wants.atom do
render :layout => false
end
end
end

And buried inside my index.atom.builder there is a call to render
shared/topic like so:

entry.content(render( :partial => ‘/shared/topic’, :object =>
topic ), :type => ‘html’)

I was assuming this would find the file at shared/_topic.html.erb and
render it appropriately. No luck though, it gives me the error:

Couldn’t find template file for /shared/_topic in ["/Users/jjb/eng/app/
views"]

If I specify the full filename for the template (/shared/
topic.html.erb) it finds it, but that template has nested
“render :partial” calls without the “.html.erb” on the end so they
fail with the same error mentioned above.

Any help would be greatly appreciated.

Why not just change the file extension to something atom compliant
(.atom.xml?) What’s in this partial that you want to render?

On Jan 18, 2008 12:49 PM, jeff b [email protected] wrote:

respond_to do |wants|
entry.content(render( :partial => ‘/shared/topic’, :object =>
“render :partial” calls without the “.html.erb” on the end so they
fail with the same error mentioned above.

Any help would be greatly appreciated.


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.

The partial I want to render is a .html.erb and is used elsewhere on
the site for traditional web-browser content. I sort of assumed that
changing it to .atom.xml might make it work for the atom feed, but
likewise break for traditional web-browser content for the same
reason…

sounds like a bug. Have your reported it on Rails Trac?

Not yet. I was able to get it to work as expected. In the index
action changing this:

render :layout => false

To this:

render :template => ‘topic/index.atom.builder’, :layout => false

Seemed to do the trick. Does this sound like a bug?

On Jan 17, 11:33 pm, Keynan P. [email protected]

I found a solution for this - at least in my situation. It seems that
making the render call from within a respond_to was causing the
problem. By moving it to a seperate action and not in respond_to I
worked around this strangeness.

On Jan 17, 11:33 pm, Keynan P. [email protected]