Question

I know that I can do this in Rails:

<%="hello" %>

but is there any way to do this

<%
echo "hello"
%>

and get it to show up in the response?

Was it helpful?

Solution

Have you tried concat.

I have seen this when wandering in Rails documentation. Not sure at all since I am very new to Rails.

OTHER TIPS

What you have to write is

<% concat "bank" %>

now you can do something like

<%
  10.times do
    concat "cat"
  end
%>

for ten cat

Use concat, I've tried it and it works. However if you need to use HTML chars use:

concat(sanitize("STRING"))

or open your app/helpers/application_helper.rb and write:

def echo(str)
    concat sanitize str
end

so you can just type: echo "hello<br />\n"

You're looking for "print" or "puts", depending on whether or not you want a newline (probably not). Almost every object implements .to_s, which works also, though my feeling is that there's probably a better way to do whatever you're trying to do. Any more context on this?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top