[英]Ruby on Rails - trying to set up metatags and getting a simple HTML syntax error
我正在尝试添加一些社交标签。 特别是推文以及当前的推文数量,Facebook建议和当前的建议数量等)。
我已经设置了部分app / views / aplication / _ogmeta.html.erb,目前只有一行
<meta property="og:title" content="<%= meta.title ? DrillInvestor %>">
// also need type, image, and url
我在app / views / layout / application.html.erb中引用的
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<% ogdata = content_for?(:ogdata) ? yield(:ogdata) : {} %>
<%= render( partial: "ogmeta", locals: {meta: ogdata} ) %>
<title><%= content_for?(:title) ? yield(:title) : "Drill Investor" %></title>
<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script><![endif]-->
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
正在获取语法错误,意外出现')',并从行中期待':'
我相信您在三元运算符中缺少meta.title
为nil时的返回值。
<meta property="og:title" content="<%= meta.title ? DrillInvestor %>">
应该是这样的:
<meta property="og:title" content='<%= meta.title ? meta.title : "DrillInvestor" %>'>
Tristian Smith建议以下内容:1-将app / views / appllication / _ogmeta.html.erb更改为
<meta property="og:title" content='<%= meta[:title] || "DrillInvestor" %>'>
2-将app / views / layouts / application.htl.erb更改为
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<% ogdata = content_for?(:ogdata) ? yield(:ogdata) : Hash.new %>
<%= render "ogmeta", meta: ogdata %>
<title><%= content_for?(:title) ? yield(:title) : "Drill Investor" %></title>
<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script><![endif]-->
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
谢谢皮埃尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.