content_for Rails 4没有加载

时间:2015-03-06 05:55:54

标签: css ruby-on-rails ruby-on-rails-4 content-for

我在我的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说vendor / index.html.erb,由于content_for(main / index.html.erb)生成的css没有清除。

我尝试通过更改正文中使用的背景图片在vendor / index.html.erb中添加一些css。但是,它并没有得到反映。它仍然使用由于main / index.html.erb

中的content_for而生成的css

1 个答案:

答案 0 :(得分:0)

问题是我使用的是jquery-mobile,它的工作方式与turbolinks相同。它只是重新加载

中包含的页面部分
<div data-role="page">
    .......
</div>

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

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