In Ruby on Rails, what are KENSURE and kEND in error messages?

In Ruby on Rails, I sometimes get an error message on the page:

compilation error
/Users/jian/ror/shov2/app/views/stories/index.html.erb:13: syntax error, unexpected kENSURE , waiting for ')'
/Users/jian/ror/shov2/app/views/stories/index.html.erb:15: syntax error, unexpected kEND , waiting for ')'

KEND, I can guess that this is the end ... so it means the end of the file, but unexpectedly, it should be ")".

what about KENSURA?

+4
source share
5 answers

The kEND constant refers to the end token as if you are ending with each block of code. The guarantee block is equivalent to the finally block in other languages.

begin 1/0 rescue ZeroDivisionError puts "OH SHI-" ensure # <- THIS THING 1/1 puts "Whew, we're safe" end 

That refers to kensure.

It looks like you forgot to put a closing finger at the end of a method call or a list of method parameters.

+13
source

I had the same problem. I had <%= end %> instead of <% end %> . Thanks, John!

+4
source

Also make sure you have a do after any sentences awaiting blocks.

Doing something like

 <%= form_tag "action" %> ... <% end %> 

Raise the same error

+2
source

Check the matching of delimiters (e.g. <% %> etc.) in your ERB templates.

+1
source

the ensure keyword of exception handling.

0
source

All Articles