RJS file not rendering

Hi there,
I’ve done this before many times. But for some reason, my controller
isn’t rendering my RJS file. Here’s the setup:

In the View:

  • a call to remote_function:
<select name="state" onchange="<%=
remote_function(:url=>{:action=>:cities})%>">

In the Controller:

  • get the data that I need:
def cities
  @cities = Store.find_by_sql("select DISTINCT city from stores where
state='#{params[:state]}'")
end

I have a file called cities.rjs. However, when I run it, I get the
following error:

ActionView::MissingTemplate (Missing template stores/cities.erb in view
path app/views:vendor/plugins/easy-fckeditor/app/views):

I’ve tried creating a file called cities.erb, but that doesn’t work
either. The path is correct: I have the /views/stores folder there and
the file is where it’s supposedly looking. I can’t fathom what the issue
is here. Any help?

Thanks,
Aaron.

Hi Aaron,
On Tue, 2009-09-22 at 20:00 +0200, Aaron V. wrote:

I think you need to tell Rails what view template to use.

def cities
respond_to do |format|
format.js { @cities = Store.find_by … }
end
end

Pretty sure this will pick up the .rjs template.

HTH,
Bill

Try renaming cities.rjs to cities.js.rjs. Rails is smart enough to know
that it’s getting a JS request, so there’s no need to tell Rails to what
template to use as long as the controller method and view template
follow
the standard naming convention.
Tim

On Tue, Sep 22, 2009 at 5:36 PM, bill walton [email protected]
wrote:

end

Pretty sure this will pick up the .rjs template.

HTH,
Bill


Tim L.
Coroutine LLC
516 Tennessee St., Suite 215
Memphis, TN 38103
office: 901.312.8818
mobile: 901.490.5325
http://www.coroutine.com

Hi again,
Bah, turns out I had the right files in the wrong folder. I have an
admin/stores folder and a plain old stores folder, and my partials and
RJS were in the admin version Stupid!

Thanks,
Aaron.