【问题标题】:Getting Error "ExecJS::ProgramError in Subjects#index" in Lynda.com Rails Tutorial在 Lynda.com Rails 教程中出现错误“ExecJS::ProgramError in Subjects#index”
【发布时间】:2016-03-10 15:22:54
【问题描述】:

首先让我说对不起,如果我没有尽可能清楚地解释我的问题,我对 Ruby on Rails 非常陌生,这是我第一次在这里提出问题而不是立即在这里找到答案。

我正在学习 Ruby on Rails 4 基础培训教程,并且正在研究涉及资产的部分,其中我导入了两个样式表(“admin.css”和“public.css”),然后更改了应用程序中的代码.css 样式表来包含这两个文件。

然后我创建了一个名为 admin.html.erb 的新布局,并插入了以下行来引用新样式表:

<%= stylesheet_link_tag('application', :media => 'all') %>

但是现在我在我的应用中加载任何页面时都会收到以下错误:

我在这里看到了几个类似的问题,但他们所有的代码在我的下面都有另一行引用需要修复的 JavaScript。通常第二行被更改为:

<%= stylesheet_link_tag('default', :media => 'all') %>

但这只是为了不加载样式表。

这是我的文件: admin.html.erb 布局

<!DOCTYPE html>
<html>
<head>
    <title>Simple CMS | <%= @page_title || "Admin" %></title>
    <%= stylesheet_link_tag('application', :media => 'all') %>
</head>
<body>
    <div id="header">
        <h1>Simple CMS Admin</h1>
    </div>
    <div id="main">
        <% if !flash[:notice].blank? %>
            <div class="notice">
                <%= flash[:notice] %>
            </div>
        <% end %>
        <div id="content">
            <%= yield %>
        </div>
    </div>
    <div id="footer">
        <p id="copywright">&copy; lynda.com / Brian Arpaio</p>
    </div>
</body>
</html>

application.css 样式表:

/*
* 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.
*
*= require_tree .
*= require public
*= require admin
*= require_self
*/

我的主题 index.html.erb 视图:

<% @page_title = "Subjects" %>
<div class="subjects index">
  <h2>Subjects</h2>

<%= link_to("Add new subject", {:action => 'new'}, :class => 'action new') %>

<table class="listing" summary="Subject list">
    <tr class="header">
        <th>&nbsp;</th>
        <th>Subject</th>
        <th>Visible</th>
        <th>Pages</th>
        <th>Actions</th>
    </tr>
    <% @subjects.each do |subject| %>
    <tr>
        <td><%= subject.position %></td>
        <td><%= subject.name %></td>
        <td class="center"><%= status_tag(subject.visible) %></td>
        <td class="center"><%= subject.pages.size %></td>
        <td class="actions">
            <%= link_to("Show", {:action => 'show', :id => subject.id}, :class => 'action show') %>
            <%= link_to("Edit", {:action => 'edit', :id => subject.id}, :class => 'action edit') %>
            <%= link_to("Delete", {:action => 'delete', :id => subject.id}, :class => 'action delete') %>
        </td>
    </tr>
    <% end %>
</table>

我的 gem 文件:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.1'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.13', '< 0.5'
# 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]

对不起,如果这是太多/太少的信息。任何帮助将不胜感激,谢谢!

【问题讨论】:

  • 你有没有试过把 gem 'execjs' 放到 GemFile 中,并绑定它?
  • 看起来是这样,谢谢!
  • 我在同一个教程上。在 gem 文件中添加 (gem 'execjs') 并运行 bundle install 并没有解决我的错误。还有其他选择吗?

标签: css ruby ruby-on-rails-4


【解决方案1】:

好的!这为我修好了。此问题主要发生在 Windows 操作系统中。强制您的 Coffee Script Source 版本为 1.8.0。不正确支持更高版本。

更改或将其添加到您的 gem 文件中:

gem 'coffee-script-source', '1.8.0'

然后更新 coffee-script-source 包

bundle update coffee-script-source

这应该可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-30
    • 2015-04-09
    • 1970-01-01
    • 2016-06-22
    • 2015-03-30
    相关资源
    最近更新 更多