2017-01-28 2 views
2

私はAPIを含む私の最初のプロジェクトに取り組んでいます。"e;と'をレールで適切な文字に変換する

私が働いているAPIは、私のような文字列を与える:

"In our nation’s capital, killings have risen by 50 percent." 

を私は単に文字にコードを変換することができます方法はありますか?またはgsub番を何度も呼び出す必要がありますか?

+1

https://rubygems.org/gems/htmlentities –

答えて

3
: [email protected]; sudo gem install htmlentities 
Successfully installed htmlentities-4.2.4 
: [email protected]; irb 
irb(main):001:0> require 'htmlentities' 
=> []irb(main):002:0> HTMLEntities.new.decode "¡I'm highly annoyed with character references!" 
=> "¡I'm highly annoyed with character references!" 

How do I encode/decode HTML entities in Ruby?

私は、これはあなたを助ける願っています。あなたはそれがうまくHTMLを表示する行の下に試すことができるのRubyでRailsでは

0

<%="&quot;In our nation&rsquo;s capital, killings have risen by 50 percent.&quot;".html_safe%> 

これは、出力は次のようになります:「私たちの国の首都で、殺人は50%上昇しています。」

関連する問題