# Expected kelse

**URL:** <https://www.ruby-forum.com/t/expected-kelse/135754>\
**Category:** Ruby\
**Created:** [April 24, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/expected-kelse/135754 "2008-04-24T17:21:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [April 24, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/expected-kelse/135754/1 "2008-04-24T17:21:29Z")

</div>

The following piece of code returns:  
syntax error, unexpected kELSE, expecting kEND

When I delete this block of code all works well - I have read that  
this may be an issue with copied or pasted code, UTF-8 issues etc…

I have tried all of these - is there simply something wrong with my  
code that I am not seeing?

\<% if c.amount \< 500 %\>  
\<% @project.budgmonthexpends.find(:all, :conditions =\>  
[:year\_id == c.year\_id]).each do |d| %\>  
\<% else %\>   
\<removed\_email\_address@domain.invalid(:all, :conditions =\> :year\_id  
== c.year\_id).each do |d|%\>  
\<% end %\>

Thanks,  
Erik

---

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [April 24, 2008, 5:35pm UTC](https://www.ruby-forum.com/t/expected-kelse/135754/2 "2008-04-24T17:35:13Z")

</div>

On 24 Apr 2008, at 16:20, erik wrote:

> ```
> <% @project.budgmonthexpends.find(:all, :conditions =>
> 
> ```
> 
> [:year\_id == c.year\_id]).each do |d| %\>  
> \<% else %\>   
> \<removed\_email\_address@domain.invalid(:all, :conditions =\> :year\_id  
> == c.year\_id).each do |d|%\>  
> \<% end %\>
> 
> Thanks,  
> Erik

You never finish (or do anything with) the block from the line above,  
you have to end that block with ‘end’ before your ‘else’ statement.

if c.amount \< 500  
@project.budgmonthexpends.find(:all, :conditions =\> [:year\_id ==  
c.year\_id]).each do |d|  
end  
else  
@project.budgmonthexpends.find(:all, :conditions =\> :year\_id ==  
c.year\_id).each do |d|  
end  
end

Is valid code (though still gibberish since you’re not doing anything  
with the two each blocks). Hope that helps.

Alex G.

Department of Biochemistry  
University of Cambridge

---

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [April 24, 2008, 5:38pm UTC](https://www.ruby-forum.com/t/expected-kelse/135754/3 "2008-04-24T17:38:46Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

erik wrote:  
| The following piece of code returns:  
| syntax error, unexpected kELSE, expecting kEND  
|  
| When I delete this block of code all works well - I have read that  
| this may be an issue with copied or pasted code, UTF-8 issues etc…  
|  
| I have tried all of these - is there simply something wrong with my  
| code that I am not seeing?

Removing the ERb cruft:

if c.amount \< 500  
~ @project.budgmonthexpends.find(:all, :conditions =\>  
[:year\_id == c.year\_id]).each do |d|  
~ else  
~ @project.budgmonthexpends.find(:all, :conditions =\>  
~ :year\_id == c.year\_id).each do |d|  
~ end

Stuffing an ‘else’ in a block makes Ruby throw an error, obviously.

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)

~ - You know you’ve been hacking too long when…  
…you get snail mail, and you think to your self "You have new mail on  
node “your\_address” from user “name\_on\_the\_frank”.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkgQqNAACgkQbtAgaoJTgL9qZwCfQEmZTKTuIZLneB3NINWKVXOr  
WKQAnj84e3tV9mkGITpgbqY0BTq1OGUk  
=jPbH  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [April 24, 2008, 7:07pm UTC](https://www.ruby-forum.com/t/expected-kelse/135754/4 "2008-04-24T19:07:18Z")

</div>

- Phillip G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) (17:35) schrieb:

> if c.amount \< 500  
> ~ @project.budgmonthexpends.find(:all, :conditions =\>  
> [:year\_id == c.year\_id]).each do |d|  
> ~ else  
> ~ @project.budgmonthexpends.find(:all, :conditions =\>  
> ~ :year\_id == c.year\_id).each do |d|  
> ~ end
> 
> Stuffing an ‘else’ in a block makes Ruby throw an error, obviously.

Besides that, how is »[:year\_id == c.year\_id]« or »:year\_id ==  
c.year\_id« supposed to work?

mfg, simon … l

---

<div class="post-metadata">

**Author:** ![erik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@erik](https://www.ruby-forum.com/u/erik)\
**Post date:** [April 26, 2008, 6:37am UTC](https://www.ruby-forum.com/t/expected-kelse/135754/5 "2008-04-26T06:37:44Z")

</div>

I think your  
previous line  
\<% @project.budgmonthexpends.find(:all, :conditions =\>  
[:year\_id == c.year\_id]).each do |d| %\>

is missing the block of code to execute… which should end with an  
‘end’, but the else is seen prior to the end required to end the block.

RF
