首页
\
问答
\
如何在元标记中使用html_safe:在rails上的ruby中的描述内容(how to use html_safe in meta tag og:description content in ruby on rails)
如何在元标记中使用html_safe:在rails上的ruby中的描述内容(how to use html_safe in meta tag og:description content in ruby on rails)
我像这样使用og:description meta标签
<meta property="og:description" content="<%= @post.description.html_safe %>" />
但它在页面顶部显示了帖子的描述。
I use og:description meta tag like this
<meta property="og:description" content="<%= @post.description.html_safe %>" />
But it shows description of post in top of the page.
更新时间:2021-11-13 14:11
最满意答案
我在我的PHP代码中遇到此错误以显示og文件。 我想,它会在轨道上工作。 你只需将
""
改成''
<meta property="og:description" content='<%= @post.description.html_safe %>'/>
要么
<meta property="og:description" content='<%= @post.description %>'/>
我希望这对你有帮助。
I have ever got this error in my php code to show og file. I thought, It will work to in rails. You just change
""
into''
<meta property="og:description" content='<%= @post.description.html_safe %>'/>
or
<meta property="og:description" content='<%= @post.description %>'/>
I hope this help you.
相关问答
更多-
并不是真正的答案,但在这种情况下,使用以下方法解决了问题: <%= sanitize @post.content %> Not really an answer to why but in this situation using the following resolved the issue: <%= sanitize @post.content %>
-
嗯不确定,但尝试以下内容: doc.css(".row").map do |row| date = row.css(".itemdate").text a_tag = row.css("a")[0] text = a_tag.text link = a_tag[:href] if date = "#{month} #{day}" @string = "#{date} #{text} #{link}
" end end.html_safe 另一种方式,不是解决 ... -
我在我的PHP代码中遇到此错误以显示og文件。 我想,它会在轨道上工作。 你只需将""改成'' 要么 我希望这对你有帮助。 I have ever got this error in my php code to ...
-
它没有.html_safe因为@chapter.chaptext .html_safe被渲染为textcontainer的字符串。 我认为问题是class = 'getannotation'覆盖你的样式(引导类)或者id = 'textcontainer'和样式规则,如#textcontainer p { font-size: 20px;} 使用Web检查器工具查看对chaptext内容应用的样式及其来源(CSS类)。 It works without .html_safe because @chapter ...
-
好吧,看起来我现在已经开始工作了。 看着Ruby文档,找到了CGI类和unescapeHTML方法。 我在窗体中使用富文本编辑器将文本保存到数据库。 显然,因为html被转义发送到数据库,我需要撤消转义,然后调用html_safe。 这就是它在数据库中的显示方式: <strong>howdy</strong> 我将它应用于我的帮助器方法,现在html显示为html而不是标签。 def safe(content) "#{ CGI::unescapeHTML(content) }". ...
-
问题字符串是否包含额外的p标签? 如果是这样,它将无法正常工作,因为您无法在p中嵌套p 。 你能改变包装到一个div吗? 这应该解决它。 IE <%= content_tag :div, question.html_safe, class: 'style1' %> 或者,从问题中去掉任何p标签: <%= content_tag :div, question.gsub(/<\/?p>/, '').strip.html_safe, class: 'style1' %> Does the question s ...
-
在这种情况下,我经常明确地逃避不安全的部分: "» #{h @category.name}".html_safe In this situation I often explicitly escape the unsafe part: "» #{h @category.name}".html_safe
-
根据聊天讨论,OP正在S3上托管图像。 因此,定义meta标记如下: 这将被评估为: 注意: 如果图像存储在您自己的应用程序服务器上,那么您可以将其用作:当您在Ruby on Rails中连接字符串时,每个未标记为html_safe的字符串在连接之前首先被转义。 使用第二个代码段,确保在每个字符串上调用.html_safe(包括常量,如: "
相关文章
更多- Why Ruby
- HTML meta标签
- Rails 风格指导
- 关于微信公众号内嵌网页的几个meta标签
- Rails常用插件
- 怎么高效率从Tag 里面抽取有用信息
- 删除Hbase的META中多余表项
- rails页面文件html.erb如何访问ActiveRecord的资源
- Rails中的路由功能是如何对应的?
- Rails设置环境变量
最新问答
更多- 在csproj中使用appdata环境变量(Use appdata environment variable in csproj)
- 从背景返回后,Skobbler Map崩溃(Skobbler Map crashes after returning from background)
- 如何保持对绑定服务的轮询?(How to keep polling a bound service?)
- ASP.NET单选按钮jQuery处理(ASP.NET radio button jQuery handling)
- Linux上的FORTRAN图形库(FORTRAN graphic library on Linux)
- 我们如何根据索引更新dynamodb表(不基于primary has和range key)(how can we update dynamodb table based on index(not based on primary has and range key))
- 功能包装避免重复(wrap of functions avoid duplicating)
- Android BroadcastReceiver和Activity.onPause()(Android BroadcastReceiver and Activity.onPause())
- 无法使用phonegap 2.4在Android上播放录音(unable to play audio recordings on android using phonegap 2.4)
- VS2015 + Resharper:不要使用C#6(VS2015 + Resharper: Don't use C#6)
- 大学电脑四级对初学者来说要多久能过
- 特殊字符删除?(Special characters remove?)
- Android视频教程现在网上的都比较零散呢?有些太坑爹了,感觉老师就是在想当然的讲
- 计算同一个表中不同行之间的差异[重复](Calculate delta's between different rows in same table [duplicate])
- Javaweb开发,技术路线是什么?该怎么写?
- JavaScript只在php代码中执行一次(JavaScript only executes once inside php code)
- 不兼容的字符编码:ASCII-8BIT和UTF-8(incompatible character encodings: ASCII-8BIT and UTF-8)
- Clojure(加载文件)给出错误(Clojure (load-file) gives an error)
- 为具有瞬态scala依赖性的spring-xd项目优化gradle(Optimize gradle for spring-xd project with transient scala dependency)
- 如何才能在Alpha测试模式下发布我的应用程序?(How can I publish my app in Alpha test mode only?)
- “没有为此目标安装系统映像”Xamarin AVD Manager(“No system images installed for this target” Xamarin AVD Manager)
- maven中的Scalatest:JUnit结果(Scalatest in maven: JUnit results)
- 使用android SDK将文件直接上传到存储桶中的文件夹(Upload a file directly to a folder in bucket using android SDK)
- 是否应将plists导入CoreData?(Should plists be imported to CoreData?)
- java.lang.reflect.InvocationTargetException JavaFX TableView(java.lang.reflect.InvocationTargetException JavaFX TableView)
- 根据唯一列值动态创建多个子集(Dynamically create multiple subsets based on unique column values)
- 使用CSS可以使HTML锚标签不可点击/可链接吗?(Is it possible to make an HTML anchor tag not clickable/linkable using CSS?)
- 嵌套的模板可能性(Nested template possibilities)
- 任何方式在iOS7 +上以编程方式打开蓝牙(Any way to turn on bluetooth programmatically on iOS7+)
- 如何为给定的SQL查询编写JPA查询(How I can write JPA query for given SQL query)