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

前端 未结 4 1632
小鲜肉
小鲜肉 2021-02-07 08:37

I know that I can do this in Rails:

<%=\"hello\" %>

but is there any way to do this

<%
echo \"hello\"
%>

4条回答
  •  爱一瞬间的悲伤
    2021-02-07 09:11

    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
    \n"

提交回复
热议问题