This code is executed from a view, and it works:
<% @metaTags = OpenGraph.fetch('http://www.someurl.com') || nil %>
<% if @metaTags != nil %>
postTitle = truncateStr('<%= @metaTags.title %>', 72);
<% end %>
I'd like to do the same but passing http://www.someurl.com
as a javascript-computed parameter, like this
Attempt 1
var someURL = ... (compute value);
setCookie("someURL", someURL, 10000);
<% @metaTags = OpenGraph.fetch(cookies[:someURL]) || nil %>
<% if @metaTags != nil %>
postTitle = truncateStr('<%= @metaTags.title %>', 72);
<% end %>
It doesn't work.
Attempt 2
var someURL = ... (compute value);
setCookie("someURL", someURL, 10000);
<% readPostURL %>
<% if @metaTags != nil %>
postTitle = truncateStr('<%= @metaTags.title %>', 72);
<% end %>
and in controller
private
def readPostURL
@metaTags = OpenGraph.fetch(cookies[:postURL]) || nil
end
helper_method :readPostURL
It doesn't work either.
Both scenarios seem to have troubles with the cookies. Is there a way to run OpenGraph.fetch(parameter) from a view with some javascript variable
?