简体   繁体   中英

Ruby on Rails: How do you display “raw” erb tags in views?

For example, I want to display <%= @location.country %> in views to the user. So if the user visits http://domain.com/tutorials/123 , he'll see <%= @location.country %> . That is, Rails doesn't process that portion.

I'm thinking something along the lines of <*= @location.country %> , but of course that doesn't work. Any ideas?

你添加第二个%。

<%%= @location.country %>

You need to use html entities for the < ( &lt; ) and > ( &gt; ). So something like &lt;%= @location.country %&gt; will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM