简体   繁体   English

Ruby on Rails:如何在视图中显示“原始”erb标记?

[英]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. 例如,我想在视图中向用户显示<%= @location.country %> So if the user visits http://domain.com/tutorials/123 , he'll see <%= @location.country %> . 因此,如果用户访问http://domain.com/tutorials/123 ,他会看到<%= @location.country %> That is, Rails doesn't process that portion. 也就是说,Rails不处理该部分。

I'm thinking something along the lines of <*= @location.country %> , but of course that doesn't work. 我正在考虑<*= @location.country %> ,但当然这不起作用。 Any ideas? 有任何想法吗?

你添加第二个%。

<%%= @location.country %>

You need to use html entities for the < ( &lt; ) and > ( &gt; ). 您需要为<&lt; )和>&gt; )使用html实体。 So something like &lt;%= @location.country %&gt; 所以类似于&lt;%= @location.country %&gt; will work. 将工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Rails中的输入标记中存储erb值? - How do you store an erb value inside input tags in Rails? Rails:如何在视图中而不是application.html.erb中包括元标记? - Rails: How to include meta tags in views and not in application.html.erb? 如何在Rails html.erb文件的ruby if / else循环中执行一些jQuery? - How do you do some jQuery inside a ruby if/else loop in a Rails html.erb file? 您如何在 Rails 6 上使用/ERB Ruby 迭代一系列数字? - How do you iterate over a range of numbers with each do with/ ERB Ruby on Rails 6? 如何在Ruby on Rails中创建指向.html.erb文件的链接? - How do you create a link to a .html.erb file in Ruby on Rails? 如何在Ruby on Rails中从views / controller_name / page1.html.erb链接到公用文件夹中的项目? - How do I link to an item in the public folder from views/controller_name/page1.html.erb in Ruby on Rails? 如何在Ruby on Rails中的html erb文件中有条件地显示div - How to conditionally display a div inside a html erb file in Ruby on Rails 如何在Rails上的ruby中显示html? - how do you display a html in view on ruby on rails? 如何在轨道上 ruby 的视图中显示关联模型 - how to display associated models in views in ruby on rails 如何在ERB do语句中使用CSS类 Ruby on Rails - How To Use A CSS Class in an ERB Do Statement | Ruby on Rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM