RJS/link_to_remote error

I’m trying to build an WebFTP application in Rails for some practice.

Here is a link located in a partial named _display_file that is called
by a partial named _list_files. A similar link is created for every
directory in the FTP

<%= link_to_remote filename ,
:url => {:action => ‘chdir’ , :ftp_dir => filename},
:update => ‘ftp_div’ %>

It should, to my understanding, make a call to the ‘chdir’ action and
use the results to update the ftp_div.

The controller action ‘chdir’ is shown below:

def chdir
@ftp = session[‘ftp’]

@ftp.chdir( params[ :ftp_dir ] )
session[‘ftp’] = @ftp
@list = @ftp.list("-a")
end

btw, I can store the ftp object inside a session because I’ve enabled
memory_cache instead of other session types. So that’s not the issue,
it works without the AJAX.

Finally the file chdir.rjs is shown below:

page.replace_html(“ftp_div” , :partial => “list_files” , :object =>
@list)

So basically, the user should be able to click on the directory and the
directory listing should be updated without a page refresh. Instead I
get this error when click on one of the links:

RJS error:

TypeError $(element) has no properties

Afterwords I get a “notice” box containing what appears to be the code
I would like to appear in the ftp_div division… It looks something
like this:

Element.update(“ftp_div”, "

etc...

with the etc… being replaced by the content that should be showing in
the browser. Any suggestions would be appreciated.

Joe S. wrote:

I’m trying to build an WebFTP application in Rails for some practice.

Here is a link located in a partial named _display_file that is called
by a partial named _list_files. A similar link is created for every
directory in the FTP

<%= link_to_remote filename ,
:url => {:action => ‘chdir’ , :ftp_dir => filename},
:update => ‘ftp_div’ %>

It should, to my understanding, make a call to the ‘chdir’ action and
use the results to update the ftp_div.

The controller action ‘chdir’ is shown below:

def chdir
@ftp = session[‘ftp’]

@ftp.chdir( params[ :ftp_dir ] )
session[‘ftp’] = @ftp
@list = @ftp.list(“-a”)
end

btw, I can store the ftp object inside a session because I’ve enabled
memory_cache instead of other session types. So that’s not the issue,
it works without the AJAX.

Finally the file chdir.rjs is shown below:

page.replace_html(“ftp_div” , :partial => “list_files” , :object =>
@list)

So basically, the user should be able to click on the directory and the
directory listing should be updated without a page refresh. Instead I
get this error when click on one of the links:

RJS error:

TypeError $(element) has no properties

Afterwords I get a “notice” box containing what appears to be the code
I would like to appear in the ftp_div division… It looks something
like this:

Element.update(“ftp_div”, "

etc...

with the etc… being replaced by the content that should be showing in
the browser. Any suggestions would be appreciated.

Joe,

I had the same problem before, and turns out that when you’re using RJS
templates you shouldn’t specify the :update on your link_to_remote, so
on your case you just call

<%= link_to_remote filename, :url => {:action => ‘chdir’ , :ftp_dir =>
filename} %>

Hope that helps.


Thiago J.
acts_as_solr => http://acts-as-solr.rubyforge.org

Hi Joe,

Joe S. wrote:

TypeError $(element) has no properties
I think it’s trying to tell you it can’t find a unique DOM element with
that
id. One thing you might check is to ensure that the tag


appears once, and only once, in the html page you’re producing.

hth,
Bill

Unfortunately the problem persists after removing the update tag. Thank
you for your help regardless.

Bill W. wrote:

Hi Joe,

Joe S. wrote:

TypeError $(element) has no properties
I think it’s trying to tell you it can’t find a unique DOM element with
that
id. One thing you might check is to ensure that the tag


appears once, and only once, in the html page you’re producing.

hth,
Bill

LOL, I made a stupid error. I had

instead of
id=“ftp_div”. I changed it and all is well. Thank you for your help.

Joe S. wrote:

I changed it and all is well. Thank you for your help.

Congrats and you’re welcome.

Best regards,
Bill

Joe S. wrote:

It should, to my understanding, make a call to the ‘chdir’ action and
end

Afterwords I get a “notice” box containing what appears to be the code
I would like to appear in the ftp_div division… It looks something
like this:

Element.update(“ftp_div”, "

etc...

In my experience, javascript doesn’t like double quotes (") very much.
Maybe try page.replace_html(:ftp_div … or
page.replace_html(‘ftp_div’… instead?

Regards,
Henning