使用 Rails 上的 Ruby 将 stylesheet_link_tag 中的 'default' 从 application.html.erb 更改为 'application' 时出错
Error when changing 'default' to 'application' in stylesheet_link_tag from application.html.erb using Ruby on Rails
我正在从头开始构建一个新应用程序。上周刚开始学习RoR。
我一直在学习完美的教程 except:
我正在尝试安装 Bootstrap 时出现错误。
所以:
Windows 10
我工作的环境版本是:
Ruby 2.2.4 Rails 4.2.5.1
逐步按照https://github.com/twbs/bootstrap-sass
的说明进行操作。 (安装宝石,放置 @import
行等)
我得到的错误如下:
ExecJS::ProgramError...
...application.html.erb where line #5 raised:
TypeError: Object doesn't support this property or method
Google 搜索并找到 解决方案:
如果我在 application.html.erb 中从 'application' 更改为 'default',错误就会消失,但我没有得到 bootstrap 样式。 一切恢复正常。
文件:
宝石文件
source 'https://rubygems.org'
gem 'rails', '4.2.5.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
group :development, :test do
gem 'sqlite3'
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
end
group :test do
gem 'minitest-reporters'
gem 'mini_backtrace'
gem 'guard-minitest'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
application.css.scss
/*
* 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 any plugin's vendor/assets/stylesheets directory 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.
*
*/
@import "bootstrap-sprockets";
@import "bootstrap";
application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
application.html.erb
<%= stylesheet_link_tag 'application', :media => "all" %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %> ...
我遇到的另一个问题:
当使用 link_to
作为 destroy
的动作时,似乎没有任何变化。
谷歌搜索,我发现如果我更改为 button_to
,destroy
操作将完美运行,但我认为这是一个应该更正的问题。
所以我通过以下操作修复了它:
- 下载node.js并安装。
- 在此处找到 ExecJS 的
runtimes.rb
文件:\RUBYINSTALLATIONFOLDER\lib\ruby\gems.2.0\gems\execjs-2.6.0\lib\execjs
并将其更改为 ExecJS::RuntimeError on Windows trying to follow rubytutorial 的答案选项 3
我正在从头开始构建一个新应用程序。上周刚开始学习RoR。 我一直在学习完美的教程 except:
我正在尝试安装 Bootstrap 时出现错误。
所以:
Windows 10
我工作的环境版本是:
Ruby 2.2.4 Rails 4.2.5.1
逐步按照https://github.com/twbs/bootstrap-sass
的说明进行操作。 (安装宝石,放置 @import
行等)
我得到的错误如下:
ExecJS::ProgramError...
...application.html.erb where line #5 raised:
TypeError: Object doesn't support this property or method
Google 搜索并找到 解决方案:
如果我在 application.html.erb 中从 'application' 更改为 'default',错误就会消失,但我没有得到 bootstrap 样式。 一切恢复正常。
文件:
宝石文件
source 'https://rubygems.org'
gem 'rails', '4.2.5.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
group :development, :test do
gem 'sqlite3'
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
end
group :test do
gem 'minitest-reporters'
gem 'mini_backtrace'
gem 'guard-minitest'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
application.css.scss
/*
* 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 any plugin's vendor/assets/stylesheets directory 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.
*
*/
@import "bootstrap-sprockets";
@import "bootstrap";
application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
application.html.erb
<%= stylesheet_link_tag 'application', :media => "all" %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %> ...
我遇到的另一个问题:
当使用 link_to
作为 destroy
的动作时,似乎没有任何变化。
谷歌搜索,我发现如果我更改为 button_to
,destroy
操作将完美运行,但我认为这是一个应该更正的问题。
所以我通过以下操作修复了它:
- 下载node.js并安装。
- 在此处找到 ExecJS 的
runtimes.rb
文件:\RUBYINSTALLATIONFOLDER\lib\ruby\gems.2.0\gems\execjs-2.6.0\lib\execjs
并将其更改为 ExecJS::RuntimeError on Windows trying to follow rubytutorial 的答案选项 3