Link_to_remote still looks for view.html.erb?

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' } %>   ...

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 -%>

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

Awesome, thank you that worked!

Mark

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs