Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing To The Response in Rails? (Like "echo" in PHP)

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?

like image 768
Dan Rosenstark Avatar asked Feb 02 '09 20:02

Dan Rosenstark


3 Answers

Have you tried concat.

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

like image 85
Vincent Robert Avatar answered Oct 13 '22 22:10

Vincent Robert


What you have to write is

<% concat "bank" %>

now you can do something like

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

for ten cat

like image 30
Bank Avatar answered Oct 13 '22 22:10

Bank


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"

like image 6
TesX Avatar answered Oct 13 '22 21:10

TesX