Ruby on rails 资产管道不';t在'工作;应用程序.scss';在我的Rails 4.2应用程序中
我是Rails新手,如果这是一个愚蠢的问题,我道歉。但我无法解决我的问题:我在我的新应用程序中添加了Bootstrap,但它仍然没有使用任何新样式 我已将application.css重命名为application.scss,并创建了这样的结构:Ruby on rails 资产管道不';t在'工作;应用程序.scss';在我的Rails 4.2应用程序中,ruby-on-rails,twitter-bootstrap,sass,ruby-on-rails-4.2,ruby-2.2,Ruby On Rails,Twitter Bootstrap,Sass,Ruby On Rails 4.2,Ruby 2.2,我是Rails新手,如果这是一个愚蠢的问题,我道歉。但我无法解决我的问题:我在我的新应用程序中添加了Bootstrap,但它仍然没有使用任何新样式 我已将application.css重命名为application.scss,并创建了这样的结构: |-stylesheets |-elements |--articles |---article.scss |-application.scss 应用程序.scss /* User styles * Plugins first
|-stylesheets
|-elements
|--articles
|---article.scss
|-application.scss
应用程序.scss
/* User styles
* Plugins first
*/
@import "bootstrap-sprockets";
@import "bootstrap";
@import "elements/**/*";
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_self
*/
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require_tree .
在我添加的Gem文件中
source 'https://rubygems.org'
ruby '2.2.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2'
# Установка Bootstrap
gem 'sass-rails'
gem 'bootstrap-sass'
#Autoprefixer optional, but recommended. It automatically adds the proper vendor prefixes to your CSS code when it is compiled.
gem 'autoprefixer-rails'
Application.js
/* User styles
* Plugins first
*/
@import "bootstrap-sprockets";
@import "bootstrap";
@import "elements/**/*";
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_self
*/
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require_tree .
我尝试在article.scs中编写任何样式规则,但我的应用程序不使用它们,因此任何引导样式都不使用它们。有一种更简单的方法,我将描述顺序: 添加
gem'bootstrap sass'
执行捆绑安装后,重新启动服务器
而不是加载项config/application.rb
下一个字符串:
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
对于您的图像,在app/assets/stylesheets
中创建custom.css.scss
,然后在那里添加@import“bootstrap”代码>,,
在您的custom.css.scss
中,您可以编写自己的样式有一种更简单的方法,我将描述顺序:
添加gem'bootstrap sass'
执行捆绑安装后,重新启动服务器
而不是加载项config/application.rb
下一个字符串:
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
对于您的图像,在app/assets/stylesheets
中创建custom.css.scss
,然后在那里添加@import“bootstrap”代码>,,
在您的custom.css.scss
中,您可以编写自己的样式我怀疑您的环境中有较旧版本的引导。尝试使用gem'bootstrap-sass',3.3.3'
更新gem文件,并运行bundle
。请确保在更新后重新启动服务器
或者,您也可以只运行包更新
我怀疑您的环境中有较旧版本的引导。尝试使用gem'bootstrap-sass',3.3.3'
更新gem文件,并运行bundle
。请确保在更新后重新启动服务器
或者,您也可以只运行包更新
几个小时后,我发现一个问题-我的pages\u控制器不正确:
class PagesController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
但我不建议这样做,因为几个小时后我发现了一个问题-我的pages\u控制器不正确:
class PagesController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
但是我不建议这样做尝试重命名文件:application.css.scss谢谢您的快速回答。但它无法尝试指定article.scs的相对路径,而不是@import“elements/***”代码>。行吗?已经做了。没用。此外,它也没有解释为什么Bootastrap样式不起作用。请尝试重命名文件:application.css.scss谢谢您的快速回答。但它无法尝试指定article.scs的相对路径,而不是@import“elements/***”代码>。行吗?已经做了。没用。此外,它也没有解释为什么在捆绑包更新后bootstrap样式不起作用一些gem被更新:安装sass 3.4.13(was 3.2.19)安装jquery rails 4.0.3(was 3.1.2)安装sass rails 5.0.1(was 4.0.5)
但我的应用程序在bundle update
之后仍然既不使用引导也不使用我自己的样式一些gem被更新了:安装sass 3.4.13(was 3.2.19)安装jquery rails 4.0.3(was 3.1.2)安装sass rails 5.0.1(was 4.0.5)
但我的应用程序仍然既不使用引导也不使用我自己的样式,因为某些原因,添加custom.css.scss文件没有帮助。我已经在我以前的应用程序中使用过这种方法,在那里我使用css而不是css.scss,而且它很有效。但在这个应用程序中,它没有。由于某些原因,添加custom.css.scss文件没有帮助。我已经在我以前的应用程序中使用过这种方法,在那里我使用css而不是css.scss,而且它很有效。但在这个应用程序中,它不是。