A function doesn't work as expected, within a view

Why does this view https://pastebin.com/raw/21tnpshE, display
puts “test” on the webpage? The view ends up with this html

But i’d have expected it to write “test”, to the console. My console only says test2

puts “test”

Hi @barilo,

Ruby code needs to be surrounded by <% and %> for Rails to process it correctly, even inside of your function. Otherwise, it gets treated as HTML. Try writing it like this instead:

<% def aaa %>
  <% puts "test" %> <!-- this will go to the console like you want -->
  puts "Test 2" <!-- this will get treated as HTML and show up on the page -->
<% end %>

<% aaa %>
1 Like

Thanks. That works and explains that.

1 Like

This topic is solved.