我有一个启用了TurboLinks的Rails 4应用程序,但是当更改页面(而不是进行完全刷新)时,无法使元标记(meta tags)刷新。我读到说需要在加载TurboLinks的JavaScript之前包含元标记,但是这没有效果。完全刷新可以解决问题,但不幸的是这不是我要找的。
layout/application.html.haml
%html
%head
%title= "Title"
- if content_for?(:meta_description)
%meta{content: (yield :meta_description), name: "description"}/
%meta{content: (yield :meta_keywords), name: "keywords"}/
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= csrf_meta_tags
%body{class: params[:controller].gsub("/", "-"), id: 'top'}
= render "shared/header"
.body-content
= render "shared/flash"
= yield
= render "shared/footer"
= render "shared/analytics"
helpers/application_helper.rb
def meta_tag(title, description)
content_for :meta_keywords do
title
end
content_for :meta_description do
description
end
这就是我称呼他们的方式
end
= meta_tag('here s my title', 'and the keywords')
谢谢