Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in Ruby on Rails, what is the kENSURE and kEND in error messages?

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

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

the kEND, i can guess that it is End... so it means End of file but unexpected, there should be a ')'.

how about the kENSURE ?

like image 432
nonopolarity Avatar asked Nov 29 '22 20:11

nonopolarity


2 Answers

The kEND constant refers to the token "end", as in what you end every code block with. An ensure block is the equivalent of a 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's what kENSURE refers to.

It sounds like you forgot to put the closing paren at the end of either a method call or a method parameter list.

like image 150
Chuck Avatar answered Dec 07 '22 01:12

Chuck


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

like image 26
B Seven Avatar answered Dec 06 '22 23:12

B Seven