Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4636

When using a Hash as a ERB templates, ruby complains about "encoding"

$
0
0

Simply to that

require 'erb'a = "aixòés una merda <%=rand(1..20)%>"c = {"id" => "aixòés una merda <%=rand(1..10)%>"}

If you run ERB.new(a).result, then all is fine:

ERB.new(a).result=> "aixòés una merda 3"

But with ERB.new(c).result ruby complains of encoding:

ERB.new(c).result/usr/lib/ruby/3.0.0/erb/compiler.rb:315:in `compile': undefined method `encoding' for {"id"=>"aixòés una merda <%=rand(1..10)%>"}:Hash (NoMethodError)        from /usr/lib/ruby/3.0.0/erb.rb:351:in `initialize'        from (irb):57:in `new'        from (irb):57:in `<main>'        from /usr/lib/ruby/gems/3.0.0/gems/irb-1.4.2/exe/irb:11:in `<top (required)>'        from /usr/bin/irb:25:in `load'        from /usr/bin/irb:25:in `<main>'

All my files are UTF-8.

Why this? How can I run this code? (I could cast c as string, but I want as Hash)


Viewing all articles
Browse latest Browse all 4636

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>