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:
- The page source shows the meta title fully and as I would expect.
- I put
logger debug @company.name
right above the meta tag and I'm seeing the expected result. - 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 !
精彩评论