このコードはビューから実行され、機能します。
<% @metaTags = OpenGraph.fetch('http://www.someurl.com') || nil %>
<% if @metaTags != nil %>
postTitle = truncateStr('<%= @metaTags.title %>', 72);
<% end %>
同じことをしたいのですが、http://www.someurl.com
このようにjavascriptで計算されたパラメーターとして渡します
試行 1
var someURL = ... (compute value);
setCookie("someURL", someURL, 10000);
<% @metaTags = OpenGraph.fetch(cookies[:someURL]) || nil %>
<% if @metaTags != nil %>
postTitle = truncateStr('<%= @metaTags.title %>', 72);
<% end %>
うまくいきません。
試行 2
var someURL = ... (compute value);
setCookie("someURL", someURL, 10000);
<% readPostURL %>
<% if @metaTags != nil %>
postTitle = truncateStr('<%= @metaTags.title %>', 72);
<% end %>
そしてコントローラーで
private
def readPostURL
@metaTags = OpenGraph.fetch(cookies[:postURL]) || nil
end
helper_method :readPostURL
それもうまくいきません。
どちらのシナリオでも、Cookie に問題があるようです。javascript を使用してビューから OpenGraph.fetch(parameter) を実行する方法はありますvariable
か?