Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails中的simple_格式在元描述中显示丑陋的html代码_Ruby On Rails_Ruby On Rails 3_Seo_Metadata_Meta Tags - Fatal编程技术网

Ruby on rails Rails中的simple_格式在元描述中显示丑陋的html代码

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

要显示文章,我在articles/show.html.haml中使用以下行

= 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)