# Rails3 Jquery link\_to

**URL:** <https://www.ruby-forum.com/t/rails3-jquery-link-to/190837>\
**Category:** Rails\
**Created:** [June 28, 2010, 11:39pm UTC](https://www.ruby-forum.com/t/rails3-jquery-link-to/190837 "2010-06-28T23:39:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tspore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a183cd/32.png) [@tspore](https://www.ruby-forum.com/u/tspore)\
**Post date:** [June 28, 2010, 11:39pm UTC](https://www.ruby-forum.com/t/rails3-jquery-link-to/190837/1 "2010-06-28T23:39:34Z")

</div>

I know that I’m missing something very simple but I setup my  
application to use for the links a remote=\> true call. In the call it  
finds the js.erb file, but doesn’t render into the browser the  
content.

LOG:

Started GET “/” for 127.0.0.1 at 2010-06-28 14:26:22 -0700  
Processing by HomeController#index as JS  
Rendered home/index.js.erb (0.3ms)  
Completed 200 OK in 12ms (Views: 11.6ms | ActiveRecord: 0.0ms)

Started GET “/” for 127.0.0.1 at 2010-06-28 14:26:25 -0700  
Processing by HomeController#index as HTML  
Rendered home/index.html.erb within layouts/application (2.0ms)  
Completed 200 OK in 6ms (Views: 5.6ms | ActiveRecord: 0.0ms)

As you can see in the html.erb it says within the layouts/application  
But with the JS call it is missing -  
my template looks like this -

- \<%= link\_to 'index', :root, :remote=\> true %\>
 //This one doesn't render in the template

```
    <li><a href="/" >Home</a></li> // This one works

```

What am I doing wrong?

The jQuery data-remote tag looks like this -  
$(‘a[data-remote],input[data-remote]’).live(‘click’, function (e)  
{  
$(this).callRemote();  
e.preventDefault();  
});  
$(‘a[data-method]:not([data-remote])’).live(‘click’, function (e){  
var link = $(this),  
href = link.attr(‘href’),  
method = link.attr(‘data-method’),  
form = $(’’),  
metadata\_input = ‘’;

```
    if (csrf_param != null && csrf_token != null) {
      metadata_input += '<input name="'+csrf_param+'"

```

value="’+csrf\_token+’" type=“hidden” /\>’;  
}

```
    form.hide()
        .append(metadata_input)
        .appendTo('body');

    e.preventDefault();
    form.submit();
});

```

Is it missing something?

---

<div class="post-metadata">

**Author:** ![tspore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a183cd/32.png) [@tspore](https://www.ruby-forum.com/u/tspore)\
**Post date:** [June 29, 2010, 3:13am UTC](https://www.ruby-forum.com/t/rails3-jquery-link-to/190837/2 "2010-06-29T03:13:12Z")

</div>

Ok I think I’m 1/2 their - I got something to load on the rjs  
template-  
$("#content").html(“fish”);  
Which renders html inside the content tag…  
But it just will render a plain tag for fish - not html code e.g.

# fish

But I think ideally it would render the same index.html.erb file so I  
wouldn’t have to maintain code in 2 places. Any suggestions how to do  
that?

---

<div class="post-metadata">

**Author:** ![tspore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/a183cd/32.png) [@tspore](https://www.ruby-forum.com/u/tspore)\
**Post date:** [June 29, 2010, 8:16am UTC](https://www.ruby-forum.com/t/rails3-jquery-link-to/190837/3 "2010-06-29T08:16:24Z")

</div>

Ok I think I figured out a simple version -  
$(’#content’).load(’/clients #index’);  
Right now I have it in my index.js.erb  
but I need to now figure out how to load it into my controller, so I  
can reduce files.
