简体   繁体   English

如何在Ruby on Rails应用程序中更改Index.html的头部?

[英]How to change the head section of Index.html in a Ruby on Rails app?

In the head section of my Ruby on Rails app I am only able to see the following CSS and JS file when I view the source code in browser. 在Ruby on Rails应用程序的头部,当我在浏览器中查看源代码时,我只能看到以下CSS和JS文件。

<link rel="stylesheet" media="all" href="/stylesheets/default.css" data-turbolinks-track="reload" />

<script src="/javascripts/default.js" data-turbolinks-track="reload">

I have added bootstrap CSS and JS files to the app/assets/stylesheets and app/assets/javascripts and have changed the application.css and application.js files. 我已将bootstrap CSS和JS文件添加到app/assets/stylesheetsapp/assets/javascripts ,并更改了application.cssapplication.js文件。 Still I am not able to see those files in source code. 仍然无法在源代码中看到这些文件。

  1. You need to require those files using require_tree . 您需要使用require_tree .要求这些文件require_tree . or explicitly 或明确地

    application.css application.css

     /* *= require self *= require_tree . */ 

    application.css application.css

     //= require self //= require_tree . 
  2. you can use content_for tag 您可以使用content_for标签

    application.html.haml application.html.haml

     %head = yield :head 

    index.html.haml index.html.haml

     = content_for :head do = javascript_include_tag "bootstrap" 

In your application.css add the following to include your files 在application.css中添加以下内容以包含文件

*= require bootstrap
*= require default
*= require_tree .
*/

Added <link rel="stylesheet" type="text/css" href="stylesheets/bootstrap.min.css"> to the application.html.erb file. 已将<link rel="stylesheet" type="text/css" href="stylesheets/bootstrap.min.css">application.html.erb文件。

Thanks to @Deepak for giving me a lead to find an alternate solution to my problem. 感谢@Deepak给我带头寻找解决我的问题的替代方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM