ERB call without Rails: undefined 'raw' method

I use the ERB engine to create a standalone HTML version of my Rails website page. The page shows when Rails is shown, but I can’t create the ERB myself (despite using the same ERB template).

First, I got the undefined method 't' error, and I solved it by replacing all calls <%=t(...)%> with <%=I18n.translate(...)%> .

Now I get the undefined method 'raw' . Should I replace all calls <%=raw(...)%> with something else? If so, then what?

+6
source share
1 answer

raw defined as an assistant in the actionpack / action_view library, so without rails you cannot use it. But ERB templating shows its output without any output:

 require 'erb' @person_name = "<script>name</script>" ERB.new("<%= @person_name %>").result # => "<script>name</script>" 

And because of this, there is an ERB::Util#html_escape method to escape

 include ERB::Util ERB.new("<%= h @person_name %>").result # => "&lt;script&gt;name&lt;/script&gt;" 
+6
source

Source: https://habr.com/ru/post/900405/


All Articles