# Ruby variable to JS in controller

**URL:** <https://discuss.rubyonrails.org/t/ruby-variable-to-js-in-controller/7540>\
**Category:** rubyonrails-talk\
**Created:** [January 21, 2007, 4:33pm UTC](https://discuss.rubyonrails.org/t/ruby-variable-to-js-in-controller/7540 "2007-01-21T16:33:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [January 21, 2007, 4:33pm UTC](https://discuss.rubyonrails.org/t/ruby-variable-to-js-in-controller/7540/1 "2007-01-21T16:33:12Z")

</div>

Hi Ma Mr,

Ma Mr wrote:

> I would be really grateful for explanation of this, I still don't know why it works, and why the previous doesn't.

The short answer is that the element (created by link\_to\_remote) that submitted the request to the server told the server via the message type (XMLHttpRequest) that the browser expected JS, not HTML, returned. Your first attempt used render which returned just the HTML you wanted displayed. Your second returned the HTML along with the JS to display it.

hth, Bill
