Nic*_*oul 6 ruby ruby-on-rails erb
我正在使用ERB引擎生成我的Rails网站页面的离线HTML版本.当Rails显示时页面显示很好,但是我自己生成ERB时遇到了麻烦(尽管使用相同的ERB模板).
首先我得到了错误undefined method 't',我通过替换所有<%=t(...)%>呼叫来解决它<%=I18n.translate(...)%>.
现在我明白了undefined method 'raw'.我应该<%=raw(...)%>用其他东西替换所有电话吗?如果有,那是什么?
raw在actionpack/action_view库中定义为helper,这样在没有rails的情况下就无法使用它.但ERB模板显示其输出没有任何转义:
require 'erb'
@person_name = "<script>name</script>"
ERB.new("<%= @person_name %>").result # => "<script>name</script>"
Run Code Online (Sandbox Code Playgroud)
并且因为这是为了逃避的目的有ERB::Util#html_escape方法
include ERB::Util
ERB.new("<%= h @person_name %>").result # => "<script>name</script>"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5074 次 |
| 最近记录: |