[英]stylesheet/css not working in rails
I am new to ruby on rails and trying to develop a web application, the problem is my css is not loading. 我刚接触ruby并尝试开发Web应用程序,问题是我的CSS没有加载。 I am using a free template and trying to connect it with the back end but nothing worked.
我正在使用免费的模板,并尝试将其与后端连接,但没有任何效果。 Only simple html buttons/ texts are loading .
仅加载简单的html按钮/文本。
application.html.erb application.html.erb
<title>InstagramApp</title>
<%= stylesheet_link_tag "default", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "default", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Start Bootstrap</a>
<%= link_to "Instagram", root_url, class: "navbar-brand" %>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<%= link_to "New Post", new_post_path %>
</li>
<%- if current_user %>
<% else %>
<li>
<%= link_to "Logout", new_user_session_path , method: :delete, confirm: "Are you sure?" %>
</li>
<%= link_to "Login", new_user_session_path %>
<li>
<%= link_to "Register", new_user_registration_path %>
</li>
<% end %>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<% flash.each do |a,b| %>
<div class="alert alert-success"> <%= b %> </div>
<% end %>
<%= yield %>
</div>
</div>
</div>
<style>body{padding-top:70px;}</style>
And in app/assets/stylesheets
there is bootstrap.css and bootstrap.min.css . 在
app/assets/stylesheets
有bootstrap.css和bootstrap.min.css 。
How do i load css in localhost? 如何在localhost中加载CSS?
如果将所有css文件放在stylesheet文件夹中,它将自动调用。如果没有,请执行rake asset:precompile并重新启动服务器。
If your using bootstrap elements, It will be better to install the bootstrap gem here . 如果您使用引导程序元素,最好在此处安装引导程序gem。 Easy to install and allows you to use all bootstrap components.
易于安装,并允许您使用所有引导程序组件。
install the following gems: 安装以下宝石:
gem 'bootstrap-sass', '~> 3.3.6'
gem 'sass-rails', '>= 3.2'
Change application.css to application.scss 将application.css更改为application.scss
app/assets/stylesheets/application.scss
In your application.scss
add 在您的
application.scss
添加
@import "bootstrap-sprockets";
@import "bootstrap";
In app/assets/javascripts/application.js
add 在
app/assets/javascripts/application.js
添加
//= require jquery
//= require bootstrap-sprockets
Now you can use any bootstrap component, without needed to apply the style, this is a much better way to use bootstrap in your rails app. 现在,您可以使用任何引导程序组件,而无需应用样式,这是在Rails应用程序中使用引导程序的更好方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.