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

**URL:** <https://www.ruby-forum.com/t/how-does-rails-decide-which-template-file-rjs-vs-html-to-use/151669>\
**Category:** Rails\
**Created:** [October 24, 2008, 10:00am UTC](https://www.ruby-forum.com/t/how-does-rails-decide-which-template-file-rjs-vs-html-to-use/151669 "2008-10-24T10:00:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![GreenValley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f14d63/32.png) [@GreenValley](https://www.ruby-forum.com/u/GreenValley)\
**Post date:** [October 24, 2008, 10:00am UTC](https://www.ruby-forum.com/t/how-does-rails-decide-which-template-file-rjs-vs-html-to-use/151669/1 "2008-10-24T10:00:10Z")

</div>

Hello,

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  
…  
if @customer.save  
…  
else  
…  
render :action =\> “new”  
end  
end

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?

Thanks
