# RJS/link\_to\_remote error

**URL:** <https://www.ruby-forum.com/t/rjs-link-to-remote-error/102613>\
**Category:** Rails\
**Created:** [December 5, 2006, 8:36pm UTC](https://www.ruby-forum.com/t/rjs-link-to-remote-error/102613 "2006-12-05T20:36:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [December 5, 2006, 8:36pm UTC](https://www.ruby-forum.com/t/rjs-link-to-remote-error/102613/1 "2006-12-05T20:36:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [December 5, 2006, 9:08pm UTC](https://www.ruby-forum.com/t/rjs-link-to-remote-error/102613/2 "2006-12-05T21:08:44Z")

</div>

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](http://acts-as-solr.rubyforge.org)

---

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [December 5, 2006, 9:58pm UTC](https://www.ruby-forum.com/t/rjs-link-to-remote-error/102613/3 "2006-12-05T21:58:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [December 5, 2006, 9:35pm UTC](https://www.ruby-forum.com/t/rjs-link-to-remote-error/102613/4 "2006-12-05T21:35:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [December 5, 2006, 10:16pm UTC](https://www.ruby-forum.com/t/rjs-link-to-remote-error/102613/5 "2006-12-05T22:16:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [December 5, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/rjs-link-to-remote-error/102613/6 "2006-12-05T23:18:57Z")

</div>

Joe S. wrote:

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

Congrats and you’re welcome.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![jsimone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@jsimone](https://www.ruby-forum.com/u/jsimone)\
**Post date:** [December 5, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/rjs-link-to-remote-error/102613/7 "2006-12-05T22:46:47Z")

</div>

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
