How does rails decide which template file (rjs vs html) to use?


My application sometimes renders js.rjs template for an action and
other times it tries to render html.erb template. Since, I do not
have an html.erb template for the action, I get an error. I am trying
to figure out how rails decides to use rjs vs html template so that I
can solve the issue. I use rails 2.1.0.

Here is what do:

I use a link_to_remote link to bring up a dialog:

<%= link_to_remote ‘New Customer’, {:url =>new_customer_path,:method
=> :get}%>

The code above above causes customers/new.js.rjs template to be
rendered. No problem here. In new.js.rjs template I use
page.replace_html to bring up the dialog, which in turn contains a
remote_form_for statement to post the form:
<% remote_form_for(customer,:html => {:name =>“dialog”})do |f| %>

So far so good. In customers_controller, I have:
def create



render :action => “new”

So, if the validation of customer model fails, I try to bring up the
dialog back again with errors. Most of the time, rails successfully
renders new.js.rjs template again and user sees the dialog. However,
once in a while, when the validation fails, rails tries to render
new.html.erb, which does not exist. The user does not see anything
and is not even aware of the problem. User thinks application does
not respond.

Can someone shed some light on how rails decides to use which template
file? I think it has something to do with Ajax vs no-Ajax, but what
exactly is the criteria?