gpt4 book ai didi

css - content_for Rails 4 未加载

转载 作者:行者123 更新时间:2023-11-28 08:18:01 26 4
gpt4 key购买 nike

我的 application.html.erb 中有这个

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= stylesheet_link_tag "application","jquery.mobile-1.4.5" %>
<%= javascript_include_tag "application","jquery.mobile-1.4.5" %>
<%= csrf_meta_tags %>
<%= yield(:head) %>
</head>

我的 main/index.html.erb 文件有这个:

<%= content_for :head do %>
<style type="text/css">
body {
display: table;
position: relative;
width: 100%;
height: 100%;
background: url(/assets/main/background.jpg) no-repeat center center scroll;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
.center-wrapper{
margin: 0 auto;
text-align: center;
vertical-align: middle;
}
.ui-page {
background: transparent;
}
.ui-content{
background: transparent;
}
</style>
<% end %>

这是根 url 并正确加载。在此之后,如果我导航到任何其他 url,比如 vendors/index.html.erb,由于 content_for (main/index.html.erb) 生成的 css 不会被清除。

我试图通过更改正文中使用的背景图像来将一些 css 放入 vendors/index.html.erb 中。但是,它没有得到反射(reflect)。它仍然使用因为 content_for 在 main/index.html.erb 中生成的 css

最佳答案

问题是我使用的是 jquery-mobile,它的工作方式与 turbolinks 相同。它只是重新加载页面中包含的部分

<div data-role="page">
.......
</div>

具有页面特定 css/js 的链接需要添加到页面的 head 标记中。为此,有必要在没有 ajax 的情况下调用页面并重新加载它。所以你需要使用:

rel="external", data-ajax="false" or target attributes

关于css - content_for Rails 4 未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28893112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com