开发者

Including .erb in Facebook <meta> tags

I've been having a lot of trouble getting Facebook to recognize <meta> tags that contain .erb. Here's an example:

<meta property="og:title" content="Projects <%= @company.name.present? ? ('with ' + @company.name) : '' %>" />

Here's a few details:

  1. The page source shows the meta title fully and as I would expect.
  2. I put logger debug @company.name right above the meta tag and I'm seeing the expected result.
  3. On FB, all I see is "Projects".

Do you开发者_开发技巧 know what's going on here?


Just try to use ' ' instead of " " ; ex:

   <meta property="og:description" content='<%= @job_details.description %>' />

This should not truncate the string


It's because your ruby inclusion into a string is wrong.

"Projects <%= @company.name.present? ? ('with ' + @company.name) : '' %>"
--> "Projects <%= @company.name.present? ? ('with ' + @company.name) : '' %>"

<%= "Projects #{ @company.name.present? ? ('with ' + @company.name) : '' }" %>
--> "Projects with Apple"

<%= "Projects " + @company.name.present? ? ('with ' + @company.name) : '' %>
--> "Projects with Apple"

Choose one of the two last solutions to fix your issue !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜