【发布时间】:2015-12-21 02:39:26
【问题描述】:
当我运行它时,我得到了错误: Sass::SyntaxError in Welcome#index 错误 index.html.erb:
这些是我的 ruby 文件:
<!DOCTYPE html>
<html>
<head>
<%= stylesheet_link_tag "welcome.scss" %>
</head>
<body>
<div id = "header">
<p id = "title">Welcome To Dot</p>
</div>
<h1>Make Life Easier</h1>
<h2>Enter</h2>
</body>
</html>
Welcome.scss:
#title{
font-size:30px;
font-weight: bold;
font-family: fantasy;
color: #0b1e40;
text-align: left;
}
#header{
background-color: sandybrown;
position: fixed;
z-index: 1;
}
application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>Dot</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'default', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
宝石:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
welcome_controller.rb
class WelcomeController < ApplicationController
def index
end
end
routes.rb
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'welcome#index'
end
我不确定我为什么会得到这个。如果我将“应用程序”改回“默认”,我将不再收到错误,但 CSS 不会显示在网页上。这是我的第一个 Ruby On Rails 项目,如果有任何帮助,我将不胜感激。
欢迎#index 中的 ExecJS::ProgramError 显示 C:/Users/Michael/Projects/dot/app/views/layouts/application.html.erb 其中第 5 行提出:
TypeError: 对象不支持此属性或方法 Rails.root: C:/Users/Michael/Dropbox/Docs/Homework/Projects/dot
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__35629208_74953452'
【问题讨论】:
-
您是否安装了正确的 gem 以在 Rails 中使用 SCSS/SASS?您需要安装
gem 'sass'和gem 'sass-rails'才能使 SASS 正常工作。 -
你在标题末尾缺少一个分号
color值。 -
是的,我找到了分号,但我没有安装这些 gem。我现在正在这样做,所以希望这就是问题所在!
-
SASS 是 SCSS 文件的编译器,它们将被编译并输出为普通的 CSS 文件,然后使用,因为浏览器不理解 SCSS。但是对于开发人员来说,使用 SASS 语法更容易,因为
@extend和mixins等等...... -
@AlexanderTrust 我安装了这些 gem,但我仍然收到此错误:ExecJS::ProgramError in Welcome#index
标签: ruby-on-rails