Ruby on rails Rails中的simple_格式在元描述中显示丑陋的html代码
要显示文章,我在articles/show.html.haml中使用以下行Ruby on rails Rails中的simple_格式在元描述中显示丑陋的html代码,ruby-on-rails,ruby-on-rails-3,seo,metadata,meta-tags,Ruby On Rails,Ruby On Rails 3,Seo,Metadata,Meta Tags,要显示文章,我在articles/show.html.haml中使用以下行 = simple_format(@article.content) 在broswer中查看结果非常有效。无论如何,我使用前几个词作为搜索引擎的元描述,如果文章的第一行是一个链接,它会在元描述中显示难看的html代码。例如,我有一篇文章的开头是: <p> This article is about <%= link_to 'food', 'http://test.com' %> and you c
= simple_format(@article.content)
在broswer中查看结果非常有效。无论如何,我使用前几个词作为搜索引擎的元描述,如果文章的第一行是一个链接,它会在元描述中显示难看的html代码。例如,我有一篇文章的开头是:
<p> This article is about <%= link_to 'food', 'http://test.com' %> and you can ...
在my application.html.erb中,我使用:
<meta name="description" content="<%= @content %>">
在标题中,它显示如下所示:
<meta content="<p> This article is about <%= link_to 'food', 'http://test.com' %> and you can ..." name="description">
如何确保内容仍然正确显示在浏览器中,且元描述正确,意味着:
“这篇文章是关于食物的,你可以……”只是一个想法,你可以尝试使用例如strip_标签的方法
truncate(strip_tags(@article.content), :length => 320)
未经测试,但应该有效,更多关于
truncate(strip_tags(@article.content), :length => 320)