# Erb not fully rendering .js.erb files

**URL:** <https://www.ruby-forum.com/t/erb-not-fully-rendering-js-erb-files/185160>\
**Category:** Rails\
**Created:** [March 15, 2010, 12:08pm UTC](https://www.ruby-forum.com/t/erb-not-fully-rendering-js-erb-files/185160 "2010-03-15T12:08:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba8739/32.png) [@pkh](https://www.ruby-forum.com/u/pkh)\
**Post date:** [March 15, 2010, 12:08pm UTC](https://www.ruby-forum.com/t/erb-not-fully-rendering-js-erb-files/185160/1 "2010-03-15T12:08:57Z")

</div>

(Disclaimer: I’m new to rails, and running with rails --version: Rails  
3.0.0.beta)

The quick overview of what I’m trying to do:

When the user hits a button that’s part of a table row, send an async  
POST to my server, which (assuming success) will respond with some  
javascript to twiddle the class of that table row.

All of this is happening fine, except that my js.erb file doesn’t seem  
to be being rendered correctly. I’m seeing the \<% %\> code executed  
(after throwing in a print, via WEBrick), but \<%= %\> substitutions  
aren’t being made. Note that .html.erb files come out fine.

Can anyone tell me what I’m doing wrong?

I’m making the button with:

\<%= button\_to ‘C’, correct\_result\_path(row), :remote =\> true, :method  
=\> :post %\>

The relevant controller function is:

```
def correct
  @result = Result.find(params[:id])
  @result.correct!
  @error = @result.record.save

  respond_to do |format|
    format.js
  end
end

```

My most basic “correct.js.erb” looks like this:  
\<%  
p “correct.erb.js is being processed.”  
%\>

```
var el = document.getElementById("<%=

```

escape\_javascript(@result.result\_dom\_id) =\>");  
el.setAttribute(‘class’, ‘correct-result’);

The POST response looks like this (as viewed through firebug):

```
var el = document.getElementById("<%=

```

escape\_javascript(@result.result\_dom\_id) =\>");  
el.setAttribute(‘class’, ‘correct-result’);

And here’s the WEBrick output when I POST to /results/481/correct:

```
"correct.erb.js is being processed."

```

Started POST “/results/481/correct” for 127.0.0.1 at 2010-03-15  
04:58:10  
Processing by ResultsController#correct as JS  
Parameters: {“id”=\>“481”}  
[… cut SQL tracing …]  
Rendered results/correct.js.erb (0.5ms)  
Completed in 41ms (Views: 1.9ms | ActiveRecord: 1.4ms) with 200

Thanks.

-pkh

---

<div class="post-metadata">

**Author:** ![pkh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba8739/32.png) [@pkh](https://www.ruby-forum.com/u/pkh)\
**Post date:** [March 15, 2010, 12:09pm UTC](https://www.ruby-forum.com/t/erb-not-fully-rendering-js-erb-files/185160/2 "2010-03-15T12:09:32Z")

</div>

On Mar 15, 10:34 am, pkh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> var el = document.getElementById("<%=
> 
> ```
> 
> escape\_javascript(@result.result\_dom\_id) =\>");  
> el.setAttribute(‘class’, ‘correct-result’);

You’ve closed that erb tag with =\> rather than %\>

Fred
