# Syntax error in RJS

**URL:** <https://www.ruby-forum.com/t/syntax-error-in-rjs/149231>\
**Category:** Rails\
**Created:** [September 22, 2008, 6:44pm UTC](https://www.ruby-forum.com/t/syntax-error-in-rjs/149231 "2008-09-22T18:44:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimgroom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7cd45c/32.png) [@jimgroom](https://www.ruby-forum.com/u/jimgroom)\
**Post date:** [September 22, 2008, 6:44pm UTC](https://www.ruby-forum.com/t/syntax-error-in-rjs/149231/1 "2008-09-22T18:44:07Z")

</div>

I’m new to Ruby on Rails and came across a problem I could not solve  
alone.  
I’ve a pretty simple RJS file that looks like the following:

3.times do  
page.insert\_html :bottom, ‘messages’, ‘test’  
end  
page.call ‘updateMessageWindow’

However this snippet gives a syntax error:

ActionView::TemplateError (compile error  
D:/Eigene  
Dateien/Programming/Web/AjaxChat/app/views/chat/update.js.rjs:1: syntax  
error, unexpected tIDENTIFIER, expecting kEND  
3.times do  
page.insert\_html :bottom, ‘messages’, ‘test’  
end  
page.call ‘updateMessageWindow’  
^) on  
line #1 of chat/update.js.rjs:  
1: 3.times do  
page.insert\_html :bottom, ‘messages’, ‘test’  
end  
page.call ‘updateMessageWindow’

What is wrong with it? If I remove the last line (page.call  
‘updateMessageWindow’) everything works as expected.

---

<div class="post-metadata">

**Author:** ![jimgroom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7cd45c/32.png) [@jimgroom](https://www.ruby-forum.com/u/jimgroom)\
**Post date:** [September 22, 2008, 8:43pm UTC](https://www.ruby-forum.com/t/syntax-error-in-rjs/149231/2 "2008-09-22T20:43:57Z")

</div>

On Mon, Sep 22, 2008 at 9:44 AM, Jim Gecko  
\<removed\_email\_address@domain.invalid

> wrote:

> I’m new to Ruby on Rails and came across a problem I could not solve  
> alone.  
> I’ve a pretty simple RJS file that looks like the following:
> 
> 3.times do  
> page.insert\_html :bottom, ‘messages’, ‘test’  
> end  
> page.call ‘updateMessageWindow’

Hi, you forgot the block local variable. Thus, the above should have  
been  
developed  
as follows:

3.times do |page|  
page.insert\_html :bottom, ‘messages’, ‘test’  
end  
page.call ‘updateMessageWindow’

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![jimgroom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7cd45c/32.png) [@jimgroom](https://www.ruby-forum.com/u/jimgroom)\
**Post date:** [September 22, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/syntax-error-in-rjs/149231/3 "2008-09-22T22:32:41Z")

</div>

On Sep 22, 7:31 pm, “Conrad T.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> page.insert\_html :bottom, ‘messages’, ‘test’  
> end  
> page.call ‘updateMessageWindow’

That’s not true. You don’t need the block variable (and in your  
example it’s doubly bad because you would be overwriting the magic  
page variables with the integers 0 to 2.

What’s the whole of the rjs file ?

Fred

---

<div class="post-metadata">

**Author:** ![jimgroom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7cd45c/32.png) [@jimgroom](https://www.ruby-forum.com/u/jimgroom)\
**Post date:** [September 23, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/syntax-error-in-rjs/149231/4 "2008-09-23T16:12:44Z")

</div>

Frederick C. wrote:

> On Sep 22, 7:31ï¿½pm, “Conrad T.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ï¿½page.insert\_html :bottom, ‘messages’, ‘test’  
> > end  
> > page.call ‘updateMessageWindow’
> 
> That’s not true. You don’t need the block variable (and in your  
> example it’s doubly bad because you would be overwriting the magic  
> page variables with the integers 0 to 2.
> 
> What’s the whole of the rjs file ?
> 
> Fred

Right, as it’s an rjs file it is automatically wrapped inside a block.  
After struggling a day with the code and not being able to detect any  
syntax error whatsoever I checked the encoding of the line endings. To  
my surprise they were encoded as carriage returns (CR, Mac style).  
Changing them to Linux (LF) or Windows (CR+LF) style solved the problem  
and the parser was happy again. I have no clue why my editor (intype)  
suddenly inserted CRs instead of line feeds (other files I’ve written  
with the same editor have a correct encoding of the line endings).  
To conclude, the syntax error hadn’t anything to do with RJS templates  
in special.
