Upgrading to Rails 3: <%= if expression %> raising error
-
30-10-2019 - |
Question
Ok looking over some podcasts I've seen that in Rails 3, we need to use the <%= %>
tag now when we didn't before. However just putting this in my application.html.erb file:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head></head>
<body>
<%= if true %>
true
<% end %>
</body>
</html>
does not render 'true' as I expected. Instead I get an error:
Showing /app/views/layouts/application.html.erb where line #5 raised:
/app/views/layouts/application.html.erb:5: syntax error, unexpected ')', expecting keyword_then or ';' or '\n'
');@output_buffer.append= ( if true );@output_buffer.safe_concat('
^
/app/views/layouts/application.html.erb:7: syntax error, unexpected keyword_end, expecting ')'
'); end
^
/app/views/layouts/application.html.erb:10: syntax error, unexpected keyword_ensure, expecting ')'
/app/views/layouts/application.html.erb:12: syntax error, unexpected keyword_end, expecting ')'
Extracted source (around line #5):
2: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3: <head></head>
4: <body>
5: <%= if true %>
6: true
7: <% end %>
8: </body>
going back to the old <% %>
tag fixes this problem. Is this correct? Did the rails developers decide to switch back to the old tag or am I missing something?
rails -v
gets me: Rails 3.0.5
Any ideas?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow