Respond_to strangeness

Hi, I’m in the process of RESTifying my site. Almost there and loving
it.

I started having this strange problem today.

In my controller if I have something like…

def show
@question = Question.find(2)
end

…it displays my show.rhtml file with no problems.

If if change it to this…
class QuestionsController
def show
@question = Question.find(2)
respond_to do |type|
type.html
type.js
type.xml { render :xml => @question.to_xml }
end
end

…then it starts throwing a “No rhtml, rxml, rjs or delegate template
found for questions/show.rhtml”

But it will successfully show questions/2.xml in xml format.

I can get the html to work if I change the type.html line to:
type.html { render :action => ‘show’}

My dev log doesn’t give me any clues. Any ideas?

Thanks,

Steve O.

Hi Steve,
You did define a response for a request in the xml format and you
should be doing the same thing for the html request which you are doing
in the second case by rendering the show view.
Uma

I was under the impression that I didn’t have to do define a response
like:
type.html { render :action => ‘show’ }

that just “type.html” is enough as long as I have the show.rhtml file
in my view.

What is wierd is that “type.html” was working fine without render
instructions until earlier today when I started focusing on building an
xml view.

[email protected] wrote:

I was under the impression that I didn’t have to do define a response
like:
type.html { render :action => ‘show’ }

that just “type.html” is enough as long as I have the show.rhtml file
in my view.

What is wierd is that “type.html” was working fine without render
instructions until earlier today when I started focusing on building an
xml view.

Yes you are right, the default action is to call the render method. It
still brings us to your initial issue though.
So you currently have both the .rhtml as well as the .rxml views for
the action I assume.
and how do you send the xml request ?
Try to remove the type.xml and see if it behaves the same way.
I am not sure of any other particular reason though…

So you currently have both the .rhtml as well as the .rxml views for
the action I assume.
yep, both are in my questions view directory

and how do you send the xml request ?

I was just adding .xml to the url (ie localhost:3000/questions/56.xml )

Try to remove the type.xml and see if it behaves the same way.

I tried that. As long as I have respond_to … and no explicit render
instructions next to type.html then I’ll get an error - despite the
show.rhtml file being available.

I am not sure of any other particular reason though…

It’s puzzling. thanks for your help.

Steve

Solved. It was my globalize-rails plugin that was screwing up the
respond_to.