Archive for the 'ruby' Category

Ruby errors: syntax error, unexpected kEND, expecting $end

Got this particularly nasty error without a single frame of stacktrace:

SyntaxError in PostController#show_by_id

app/controllers/post_controller.rb:36: syntax error, unexpected kEND, expecting $end

After too long time I realized I had an extra end lurking in my code!

So there you go, I should get a better editor for Ruby! Any pointers?

Convert ruby Fixnum into String

This is pretty much embarrassing simple, but what the heck. It’s Ruby, the hot new language all the kids use and I can’t be any worse.

I’ve been playing with Ruby on Rails a while now, rewrote an existing Java application in crazy short time and I am still sipping the Kool-Aid.

Well, this is a common one for newbies (even though most people use .rhtml, instead of the beautiful Haml):

TypeError in User#show

Showing app/views/user/show.haml where line #9 raised:

can't convert Fixnum into String

Extracted source (around line #9): 

Well, simple enough, just call the toString-equivalent in ruby:

to_s

. Instead of

@post.id

, use

@post.id.to_s

and you’re all set.