# Link\_to\_remote still looks for view.html.erb?

**URL:** <https://www.ruby-forum.com/t/link-to-remote-still-looks-for-view-html-erb/134665>\
**Category:** Rails\
**Created:** [April 13, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/link-to-remote-still-looks-for-view-html-erb/134665 "2008-04-13T19:29:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mslagell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mslagell](https://www.ruby-forum.com/u/mslagell)\
**Post date:** [April 13, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/link-to-remote-still-looks-for-view-html-erb/134665/1 "2008-04-13T19:29:54Z")

</div>

I know I’m missing something. Invariably, whenever I try to add some  
kind of RJS action to a page it never “just works”.

I’m working on a page that will be the user’s primary interface with  
the site. If I can, I’ll make it the only interface. I’d like all the  
other forms to come up as “dialogs” on top of the normal page. I’m  
working on the first of those now. I’ve got a link\_to\_remote tag,  
going off to a resource’s controller and the “new” action. I’ve got  
the new.rjs.erb file in the correct views sub-directory. But when I  
click on the generated tag, I get a MissingTemplate exception because  
there is no new.html.erb file. I can’t see anything in the url\_for,  
link\_to, or link\_to\_remote options that will let me explicitly set the  
content type of the request. Basically, I want the response to always  
be an rjs template. How do I make this work?

Thanks for your help!

Mark

* * *

The page with the link:  
…

 \<%= link\_to\_remote "Add Joke", :url =\> { :controller =\> 'jokes', :action =\> 'new' } %\> &nbsp; ...

The controller:

class JokesController \< ApplicationController

def new  
@joke = Joke.new  
end

end

The new.rjs.erb file:

page.insert\_html :bottom, ‘content’, :partial =\> “newJoke”, :object =\>  
@joke

The \_newJoke.html.erb file:

 \<% remote\_form\_for :newJoke do |form| -%\> \<%= form.text\_area :content, :rows =\> 10, :cols =\> 80 %\> \<% end -%\>

---

<div class="post-metadata">

**Author:** ![mslagell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mslagell](https://www.ruby-forum.com/u/mslagell)\
**Post date:** [April 14, 2008, 5:50pm UTC](https://www.ruby-forum.com/t/link-to-remote-still-looks-for-view-html-erb/134665/2 "2008-04-14T17:50:51Z")

</div>

The naming standard is now .. so try naming  
your file ‘new.js.rjs’. This will help rails figure out how to return  
‘js’ using the ‘rjs’ rendering.

You may also need to add the respond\_to block so that the framework  
understands that you want to deal with more than just the default html  
rendering:

…  
def new  
@joke = Joke.new  
respond\_to do |wants|  
wants.html # new.html.erb  
wants.js # new.js.rjs  
end  
end  
…

HTH,  
AndyV

---

<div class="post-metadata">

**Author:** ![mslagell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mslagell](https://www.ruby-forum.com/u/mslagell)\
**Post date:** [April 15, 2008, 7:40am UTC](https://www.ruby-forum.com/t/link-to-remote-still-looks-for-view-html-erb/134665/3 "2008-04-15T07:40:32Z")

</div>

Awesome, thank you that worked!

Mark
