undefined method `+@' for " ":String

Tagged:

I came across this less-than-helpful message while working on a little Rails app (hopefully more to come on that later!):
undefined method ` @' for " ":String

The code was something like:

html = '<label>'
  + check_box_tag("responses[#{code}][#{ans}]", ans)
  + ' '   answer   '<label>'

After trying a few things, I realized that Rails (Ruby, really) was complaining that the ' ' operator wasn't at the end of the line, so it wasn't trying to concatenate the strings as I expected. So flipping them to the end of the line fixed the error.
html = '<label>'  +
check_box_tag("responses[#{code}][#{ans}]", ans)  +
' '   answer   '<label>'

I was tired, or maybe I would've started that way.  In any case, hopefully this will let someone else save a few moments.  Live and learn.
 

Comments

Thanks for that tip. I had

Thanks for that tip. I had the same + sign at the beginning of the line!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <pre>, <shell>, <c>, <drupal6>, <java>, <javascript>, <objc>, <perl>, <php>, <python>, <rails>, <ruby>, <sql>, <xmlcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.